Jump to content
  • Advertisement
Sign in to follow this  
FFMG

Rotating a 2D rectangle, getting the centre

This topic is 3201 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 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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
Quote:
Original post by szecs
If V1 and v3 are the opposite vertices, then
center = (v1+v3)/2


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

thanks

FFMG

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!