Calculating Centre of changing shape

Started by
6 comments, last by luca-deltodesco 12 years, 5 months ago
you have the length of each side, but the number of sides is ever changing

for example a triangle will turn into a square and then into a octagon. How would i go about finding the centre point each time?

Thanks
Advertisement
Are the edges described in some order (i.e. clockwise)? Are the polygons convexes? In what coordinate system should the centre be described? Do you know something else?

Are the edges described in some order (i.e. clockwise)? Are the polygons convexes? In what coordinate system should the centre be described? Do you know something else?


Sorry if i wasn't descriptive. I start off with a 3d triangle in 3d space (x,y,z).
The polygons are convexes.

The things i would know = Centre point of the 3d triangle. The dimensions of each polygon. All the polygons will be the same height and width.
A new polygon (4 vertices) will be added up until there are 360 sides.

What do you mean by "A new polygon will be added up"?
Just iterate over the vertices and average the result.
Dirk Gregorius meant that you should add all point to each other and divide components of point by their number

create temporary var ( with components such as x y and z)

set them to 0.0; (all of them)

then go through all verts and add them to temporary var




then divide temporary components by the number of verts




sth like this:







t3dpoint sum(LIGHT_TRAIL tab)
{
int i;
t3dpoint result;
result.x = 0.0f;result.y = 0.0f;result.z = 0.0f;

for (i = 0; i < tab.Length; i++) {
result = vectors_add(result,tab);
}


result.x = result.x / float(tab.Length);
result.y = result.y / float(tab.Length);
result.z = result.z / float(tab.Length);


return result;

}





[/quote]




it only works for convex polys

Thank you for all the replies, I have solved it myself fortunately using the law of sines, right triangle and a ormula I developed,

Oh and what I meant by a new polygon being added up, was that I would start off with 3 polygons for the triangle (no top face or bottom face). And then add another polygon to the scene to turn it into a
square and so on, until there 360 polygons.

Just iterate over the vertices and average the result.


Assuming the polygon is a regular polygon (Which OP may be hinting at).

To OP, it doesn't matter how many edges you have or how long they are, the equation is the same:
http://en.wikipedia.org/wiki/Centroid#Centroid_of_polygon

This topic is closed to new replies.

Advertisement