Archived

This topic is now archived and is closed to further replies.

CPeX

mass point of 2D polygone

Recommended Posts

CPeX    122
can someone tell me where I can find formules to calculate the mass point coordinates of a 2D polygone. I think I can make them myself but if someone else has already done it I don''t want to do the work just over :-)

Share this post


Link to post
Share on other sites
CPeX    122
ok that''s the formule for a polygone wiht 3 points.
But my problem is the calculation of the center of mass for a polygone with more points and I don''t think that
x= (x1+x2+x3+x4+x5+....+xn)/n is the right formule

Share this post


Link to post
Share on other sites
koji187    122
in physics u would have each point ortho to earth surface and draw a line from the point to earth, for all points the center of mass would be the intersection of all the lines.
hope this helps.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
no that formule can''t be right
ex:
0----0 0----0
| | | |
| | | |
0 | | |
| | | |
0----0 0----0
0 ==> point of polygone

have the same center of mass but with x = x1+x2+...+xn/n you get two different coordinates

Share this post


Link to post
Share on other sites
CPeX    122
no that formule can''t be right
ex:
0----0 0----0
| | | |
| | | |
0 | | |
| | | |
0----0 0----0
0 ==> point of polygone

have the same center of mass but with x = x1+x2+...+xn/n you get two different coordinates

Share this post


Link to post
Share on other sites
Timkin    864
Break your polygon up into triangles. Compute the centre of mass of each triangle and it's area. Divide each triangles area by the total area of the polygon (sum of all triangle areas) and use this as the triangles weight. Take the average of each triangles centre of mass multiplied by its weight and that is the centre of mass of the polygon.

(I don't mean weight as in mass x acceleration, but rather as in 'a weighted average')

Timkin



[edited by - Timkin on March 20, 2002 9:06:00 PM]

Share this post


Link to post
Share on other sites
CPeX    122
sounds to be the right solution and even very simple to program.
I''m just wondering why I didn''t found it myself :-) it''s very simple and logic. thanks

Share this post


Link to post
Share on other sites
CPeX    122
what do you mean with 3D ?
a polygone in 3D ? ==> yes it will work
a object made of polygones ==> no it will not work

Share this post


Link to post
Share on other sites
CPeX    122
for objects made of polygones you have to split up your object in thetraëders and than calculate the center of mass for each thetraeder and thake the ''weighted average'' of the points

and a center of mass for thetraeders is x = (x1+x2+x3+x4)/4

Share this post


Link to post
Share on other sites
Timkin    864
What I described above is the formula for the first moment of a distribution - the mean - which in the case of matter is the centre of mass (the distribution is the distribution of mass in the object: it''s density function). It can be applied in n dimensions and is still the same, but rather than compute areas, you would compute volumes.

It looks simple and obvious and in some sense it is... but that''s because the density is constant throughout your polygon. It gets only slightly more complex if the density is not uniform.

Cheers,

Timkin

Share this post


Link to post
Share on other sites
CPeX    122
int(f*x dx dy dz)
xc = --------------------
int(f dx dy dz)

with f is the function who gives you the distribution of mass

but this formule isn''t simple t0 put in your game.

Share this post


Link to post
Share on other sites
Timkin    864
quote:
Original post by Dredge-Master
you guys are aware that you don''t actually have to break it up to something as small as a triangle aren''t you?



Yes Dredge, I am aware of that. It was just an easy way to present the solution so that it could be visualised as an expectation over the density function... without actually having to say that. The reason for going in this direction was that the explanation generalises to n-dimensions very easily.

For those that are interested, you can also find the centre of mass of a uniform density 2D polygon by considering a vector from an origin to each vertex of the polygon. Take the average of all vectors and that is a vector from the origin to the centre of mass of the polygon. Note: the origin CAN be one of the vertexes.

Cheers,

Timkin

Share this post


Link to post
Share on other sites
Cedric    158
quote:
Original post by Timkin
For those that are interested, you can also find the centre of mass of a uniform density 2D polygon by considering a vector from an origin to each vertex of the polygon. Take the average of all vectors and that is a vector from the origin to the centre of mass of the polygon. Note: the origin CAN be one of the vertexes.



Uhhhh... This sounds a lot like a regular arithmetic average to me. Think about what happens when you duplicate a vertex. The center of mass will be moved according to your solution, even though the shape hasn''t changed at all.

Cédric

Share this post


Link to post
Share on other sites
solson16    122
I think that a simple average of the points WILL work for any 2d or 3d figure, provided that the overall figure IS CONVEX. if the figure itself isn''t convex, then break it down into convex parts and take a weighted average from each based on the number of {points, tris?} present in that section. ( the individual tri''s method suggested would fulfill this, but, may be more than necessary)
I''m visualising this all in my head, and it seems to make sense.
of course, a counterexample would be wonderful if someone disagrees

thinking about it a bit more, that''s really computing the average polygon density, and it seems the other methods mentioned do this as well. which may not really help depending on the application. as in, if a certain large area is represented by a single square, and, elsewhere in the figure a very small area has a whole lot of detailed polys the center mass point would be skewed in that direction.

so, to get an accurate center of mass, you''d probably need to do some kind of volume based calculating. break down a certain number of polys into groups, calc the volume, calc the center point of that, and use the center points of all the subareas and take the weighted average based on the volume. this will be accurate, but, I imagine quite expensive to figure out. of course, as long as your models don''t deform in realtime, the values could be precomputed.

Share this post


Link to post
Share on other sites
Cedric    158
quote:
Original post by solson16
I think that a simple average of the points WILL work for any 2d or 3d figure, provided that the overall figure IS CONVEX. if the figure itself isn't convex, then break it down into convex parts and take a weighted average from each based on the number of {points, tris?} present in that section. ( the individual tri's method suggested would fulfill this, but, may be more than necessary)
I'm visualising this all in my head, and it seems to make sense.
of course, a counterexample would be wonderful if someone disagrees



The average of vertices won't work because of duplicate vertices. In fact, you can add a vertex on any edge of the polygon without changing the shape, and move the center of mass towards that new point. It doesn't make sense. The triangle method works, but here is a faster method
quote:
From Computer Graphics: Principles and Practice
A = 0.5 * sum[i=1 to n-1](x(i)*y(i+1) - x(i+1)*y(i))


I think this method works for concave polygons as well. I'm not exactly sure how it works, but it looks like a cross product of vectors with z = 0, and I believe the cross product gives the volume of a parallepiped, or in this case, the area of the parallelogram. I'm not going to go any further because I'm not really sure, and it's not explained in the book. It's probably just a sum of the signed area of the parallelograms.

Cédric

[edited by - cedricl on March 31, 2002 10:38:23 AM]

Share this post


Link to post
Share on other sites
solson16    122
quote:
Original post by cedricl

The average of vertices won''t work because of duplicate vertices. In fact, you can add a vertex on any edge of the polygon without changing the shape, and move the center of mass towards that new point. It doesn''t make sense. The triangle method works, but here is a faster method
Cédric



exactly, in my second two pragraphs I said that it indeed wouldn''t work, and suggested another method based on volume. take the volume of each area represented by n points, find the average of points of each area, ie that area''s center of mass, and take the average of all the centers, each weighted by the volume they represent. if you have 50 points very concentrated in a small volume, then, when their center is averaged into the total average, it''s weighted based on it''s small volume, and would have little effect on the total.

Share this post


Link to post
Share on other sites
Timkin    864
cedricl, the arithmetic average of vectors is equivalent to the geometric average of the displacements that the vectors represent...

...and who said anything about duplicating vertices? We're talking about a polygon. It has exactly n vertices, all distinct! If you add a vertex along an edge without changing the shape of the object, then you haven't added a vertex... the vertices of a polygon are the minimal set of external points that enclose the set of points IN the polygon, IF you assume that all vertices are connected by straight lines.

I must say, please read someones post and make sure you understand it before going off and canning the method suggested.

Timkin

[edited by - Timkin on April 1, 2002 8:57:06 PM]

Share this post


Link to post
Share on other sites
grhodes_at_work    1385
Whoops,

I guess I''m guilty of not totally reading the post either. My solution (via link) was for 3D polyhedra, not 2D polygons....

But if you do want to calculate mass properties for 3D polyhedra, Mirtich''s solution is fast and robust. Actually much faster than certain brute force methods.

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

Share this post


Link to post
Share on other sites
grhodes_at_work    1385
Timkin,

I didn''t sense any animosity in cedricl''s brief reply, only an observation. I don''t really see a reason for you to be defensive. Please try to calm your nerves.

quote:
Original post by Timkin
cedricl, the arithmetic average of vectors is equivalent to the geometric average of the displacements that the vectors represent...

...and who said anything about duplicating vertices? We''re talking about a polygon. It has exactly n vertices, all distinct! If you add a vertex along an edge without changing the shape of the object, then you haven''t added a vertex... the vertices of a polygon are the minimal set of external points that enclose the set of points IN the polygon, IF you assume that all vertices are connected by straight lines.

I must say, please read someones post and make sure you understand it before going off and canning the method suggested.




Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

Share this post


Link to post
Share on other sites
grhodes_at_work    1385
I would like to further comment on this conversation, to clarify the technical argument between cedricl and Timkin. Timkin, you asked cedricl to read a post carefully prior to replying, while I find his reply to be accurate and your rebuttal to his reply to be faulty, as I''ll describe. Your request to read carefully before replying is applicable to EVERYONE . (including myself, since I''m more guilty than most! .)

I consider cedricl''s comment on extra vertices to be perfectly correct (even with your constraint that vertices only truly exist at the corners of a polygon), as I''ll argue.

Suppose we add that vertex at (say), the center of an edge. Further (to satisfy your constraint), lets just slightly move the vertex normal to the edge by an infinitesimal amount so that there now two edges and an infinitesimally changed polygon with an added edge. The center of area/mass of the polygon will not have changed much at all, but the center of mass calculated by arithmetic averaging the vectors you describe may change quite a bit, especially if the starting polygon was a triangle. And if we keep subdividing that same original edge again and again, adding tens, hundreds of vertices and tens, hundreds of very small edges, the center of mass will migrate towards the collection of added edges. We can perturb that original edge so that it looks like a zig-zag, a saw-blade with teeth that are small with respect to the radius of gyration of the polygon, so that we retain the same basic mean shape of the original polygon. And eventually, in the limit, the center of mass will lie somewhere along that saw-blade edge. Clearly wrong, even for a polygon that satisfies your constraints.

quote:
Original post by Timkin
...and who said anything about duplicating vertices? We''re talking about a polygon. It has exactly n vertices, all distinct! If you add a vertex along an edge without changing the shape of the object, then you haven''t added a vertex... the vertices of a polygon are the minimal set of external points that enclose the set of points IN the polygon, IF you assume that all vertices are connected by straight lines.



Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

Share this post


Link to post
Share on other sites
Vlion    151
Some pertinent formulae from a calc book:
Given the point masses m1, m2...mn located at (x1,y1), (x2,y2)...(yn,yn)
The moment about the
y axis is My = (m1)(x1) + (m2(x2) +...+ (mn)(xn)
x exis is Mx = (m1)(y1) + (m2(y2) +...+ (mn)(yn)
I did check my variables, this is how the book gives them.

Center of mass (X,Y)(or center of gravity) is given by

X = My/m and Y = Mx/m

Where m = m1 + m2 +...+mn is the total mass of the system.

My notation is that mn is m sub n, not m times n.

So you grab each point, which has a mass.
Thats a key feature here. Each point needs a mass value.
That way you avoid a cluster of verts hauling the centerpoint towards them.

Bugle4d

Share this post


Link to post
Share on other sites