Archived

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

Finding centre of a 2D shape for rotation?

This topic is 4998 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. I have a 2d shape and i want to find out its centre about which i can rotate it. I also want to use this centre point for scaling without affecting its position. I would use this to first translate the shape so that its centre concides with origin, scale it, and then translate it back. Any simple algorithm to calculate the centre, knowing the vertices of the shape? Thanks.

Share this post


Link to post
Share on other sites
Many different types of 'center' ...

I'd just get it's maximum and minimum X and Y coords ... then

CenterX = (MinX+MaxX) *0.5
CenterY = (MinY+MaxY) *0.5

for 3d just add
CenterZ = (MinZ+MaxZ) *0.5

//edit - was: CenterZ = (MinX+MaxX) *0.5

[edited by - PyroSA on April 5, 2004 4:29:01 PM]

Share this post


Link to post
Share on other sites
Biggest problem with the average algorithm is that it screws up if there''s a high concentration of points in one area. It used mostly for problems involving varying mass density across an object (as a function of these control points) and centers of mass. But if you have something like a spaceship and you want to find the center, use the bounding box algorithm.

Share this post


Link to post
Share on other sites
quote:
Original post by PyroSA
Many different types of ''center'' ...



I''d agree. There are lots of ways to decide the center. For more complex methods, most standard Computer Graphics textbooks outline good ways of doing this, since it''s a pretty old problem.

Share this post


Link to post
Share on other sites
quote:
Original post by Astroguru
"Well, bounding boxes are simple too And fun. Don''t forget fun"

If thats what they are, can u please tell me the method?

Thanks.

Sure. Find the maximum and minimum values for the X and Y coordinates out all all the points you have. Then take the average of each set to get the center, i.e CenterX = (maxX + minX) / 2, CenterY = (maxY + minY) / 2.

Share this post


Link to post
Share on other sites