Jump to content
  • Advertisement
Sign in to follow this  

Rotating plotted 2D points.

This topic is 3916 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

I'm trying to find a way to be able to rotate points plotted around a given center. Once again the math is kicking my butt. For the sake of clarity: Say I have a point(A) at 100, 100 (x,y) and I plot another point(B) at 200,200. If point A is the center I want to be able to rotate point B around it. How do I go about doing that? Thx in advance.

Share this post

Link to post
Share on other sites
Hoping is not hw ;)

1) You have to translate your scene (all that you want to rotate, maybe only B) so that the center of the rotation is in the origin.
2) Compute the position of your objects (B) to respect to the new origin, using POLAR coordinates (angle and distance).
3) Add your rotation angle to the objects angle-coordinates.
4) Recompute cartesian coordinates.
5) Retranslate your scene to the orignial origin (I am sorry for the terminology).

In practice:
1) B'x = Bx - Ax; B'y = By - Ay
2) B'angle = atan2(B'y, B'x) <- aka arc tangent or inverse tangent
B'dist = sqrt(B'x^2 + B'y^2)
3) B'''angle = B'angle + rot_angle
4) B'''x = B'dist * cos(B''angle); B'''y = B'dist * sin(B'''angle)
5) B'''''x = B'''x + Ax; B'''''y = B'''y + Ay

atan2, sin and cos works (often) in radians, so be sure you give rot_angle in radians as well.
I hope my dumb variable naming does not confuses you!

You can spare some computation using matrix multiplication, although the procedure is less graphically intuitive:
Instead of 2) 3) 4), do
B'''x = cos(rot_angle) * B'x - sin(rot_angle) * B'y;
B'''y = cos(rot_angle) * B'y + sin(rot_angle) * B'x;

[Edited by - Nyarlath on January 31, 2008 5:55:05 AM]

Share this post

Link to post
Share on other sites
LOL no its not homework. I get out of the navy in 9 months and THEN i'll be starting school. In the mean time anything I ask is purely for personal projects. After that...who knows. /wink. J/k.

Anyways back on topic. Thank you for the info. I had something similar to your suggestion but I appear to have missed some key points. Thank you again for the help.

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!