• ### Announcements

#### Archived

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

# Finding centre of a 2D shape for rotation?

## 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 on other sites
simple algo.

Vector Centre;for(int i = 0; i < num_vertices; i ++){    Centre += vertices[i];}Centre /= (float) num_vertices;

##### 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

CenterZ = (MinZ+MaxZ) *0.5

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

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

##### 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 on other sites
he said ''simple''

##### Share on other sites
Well, bounding boxes are simple too And fun. Don''t forget fun.

##### Share on other sites
"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.

##### 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 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.

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627653
• Total Posts
2978440

• 10
• 12
• 22
• 13
• 33