Jump to content
  • Advertisement
Sign in to follow this  
Emil_Halim

Rotation question

This topic is 4115 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 All Suppose you have a 2D rectangle that has 4 points ,P1 P2 P3 and P4. how to calculate the final rectangle coordinates after rotating it by theta angle. The known data are 1- Center coordinate Cx , Cy of rectangle. 2- The half Width and half Height hWidth, halfWidth of the rectangle. 3- The Theta angle. I have tried the next calculation but it does not work correctly , so any help please ? cos_value = cos(Theta) sin_value = sin (Theta) x1 = Cx - hWidth x2 = Cx + hWidth x3 = Cx + hWidth x4 = Cx - hWidth y1 = Cy + hHeight y2 = Cy + hHeight y3 = Cy - hHeight y4 = Cy – hHeight point1.x = x1 * cos_value - y1 * sin_value point1.y = x1 * cos_value + y1 * sin_value point2.x = x2 * cos_value - y2 * sin_value point2.y = x2 * cos_value + y2 * sin_value point3.x = x3 * cos_value - y3 * sin_value point3.y = x3 * cos_value + y3 * sin_value point4.x = x4 * cos_value - y4 * sin_value point4.y = x4 * cos_value + y4 * sin_value

Share this post


Link to post
Share on other sites
Advertisement
Hi,

you are close :-)

the equation you need to is:

x' = x * cos(theta) - y * sin(theta)
y' = x * sin(theta) + y * cos(theta)

(x', y') are the rotated coordinates

So just exchange cos with sin in pointX.y

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!