# Rotating a 2D rectangle, getting the centre

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

## Recommended Posts

Hi, I have a rectangle defined as Vector v1, v2, v3, v4; (Where Vector is a simple x,y point). If I want to rotate the rectangle I need to find the centre of it, Vector vC = ...; // centre newX = cos(angle)*(v1.x-vC.x) - sin(angle)*(v1.y-vC.y) + vC.x; newy = sin(angle)*(v1.x-vC.x) + cos(angle)*(y1-y-vC.y) + vC.y; So, is my formula for the new x and y valid? and, if it is, how can I calculate the centre of the rectangle? Many thanks FFMG

##### Share on other sites
If V1 and v3 are the opposite vertices, then
center = (v1+v3)/2
I didn't check the validity of your formulas. They look fine, but there may be sign issues anyway. You can do it on a paper with a pen.

##### Share on other sites
Quote:
 Original post by szecsIf V1 and v3 are the opposite vertices, thencenter = (v1+v3)/2

of course :), how could I have forgotten this!

thanks

FFMG

1. 1
2. 2
3. 3
4. 4
Rutin
12
5. 5

• 12
• 16
• 10
• 14
• 10
• ### Forum Statistics

• Total Topics
632659
• Total Posts
3007692
• ### Who's Online (See full list)

There are no registered users currently online

×