# 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.

## 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 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 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.

You welcome :)

1. 1
Rutin
33
2. 2
3. 3
4. 4
5. 5

• 11
• 10
• 13
• 97
• 11
• ### Forum Statistics

• Total Topics
632974
• Total Posts
3009650
• ### Who's Online (See full list)

There are no registered users currently online

×