Sign in to follow this  
Ahl

Rotating plotted 2D points.

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!

[edit]
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this