[Math] Center of gravity of a self intersecting irregular polygon

algorithmsgeometry

I am trying to calculate the center of gravity of a polygon.

My problem is that I need to be able to calculate the center of gravity for both regular and irregular polygons and even self intersecting polygons.

Is that possible?

I've also read that: http://paulbourke.net/geometry/polyarea/ But this is restricted to non self intersecting polygons.

How can I do this? Can you point me to the right direction?

Sub-Question: Will it matter if the nodes are not in order? if for example you have a square shape and you name the top right point (X1Y1) and then the bottom right point (X3Y3)?

In other words if your shape is like 4-1-2-3 (naming the nodes from left to right top to bottom)

Note: Might be a stupid question but I'm not a maths student or anything!

Thanks

Best Answer

I think your best bet will be to convert the self-intersecting polygon into a set of non-self-intersecting polygons and apply the algorithm that you linked to to each of them. I don't think it's possible to solve your problem without finding the intersections, and if you have to find the intersections anyway, the additional effort of using them as new vertices in a rearranged vertex list is small compared to the effort of finding them.

To answer your subquestion: Yes, the order of the nodes does matter, especially if the polygon is allowed to be self-intersecting since in that case the order is an essential part of the specification of the polygon and different orders specify different polygons -- for instance, the "square" with the ordering you describe would be the polygon on the right-hand side of the two examples of self-intersecting polygons that the page you linked to gives (rotated by $\pi/2$).

P.S.: I just realized that different orders can also specify different non-self-intersecting (but not convex) polygons, so the only case where you could specify a polygon by its vertices alone is if you know it's convex. But even then you have to use the vertices in the right order in the algorithm you linked to.

Related Question