How to find centre of a 2D shape for rotation?

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?


work out the leftmost coordinate from your vertex set, then similarly work out the rightmost coordinate from your vertices. do the same procedure for the topmost and bottommost coordinates. after you know this bounding box of your shape, you can get the centre by x=(l-r)/2; y=(t-b)/2;

where r,l,t,b are the rightmost, leftmost, topmost and bottommost coordinates you worked out previously.

Hi !

It is very difficult to find the “center” of a shape because it all depends on what the shape look’s like, some shapes does not have any logical center and that makes it impossible.

What you could do is to find min/max values in each directions and pick the center from that, this does not always work of course, for example a banana shaped object would have it’s center a little bit outside the shape itself.