# Circular rotation or Rotation about a point

This topic is 3808 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Okay, so maybe it's late and tropical storm Fay is getting to my brain, but I can't seem to devise the formula for rotation about a point. I have a center point in 2D for several objects that make up one object and I want to rotate each one around said point keeping the same distance. I was able to deduct that I needed to rotate the objects around the circumfrence of a circle with the distance to center point being the radius. I just want to rotate 2/PI or -2/PI, but I can't seem to locate the formula online or in my math books. I'm only trying to rotate 90 degrees every time so I know that I could brute force it with a switch statement and by swapping the X, Y and negative signs to go to the right rotation, but I was wondering if there was a more elegant solution since I would like to animate the rotation. I do know how to determine the amount of angular displacement based on time: theta = ((2 * PI * r)/(time for one rotation)) * time So I can find the radian based on time to give a smooth rotation (in say a quarter second), but how do I take that and translate point A around a center point C with a radius of r with a rotation of radian R? Simple problem I know. Thanks for any help.

##### Share on other sites
You can find the equation for rotation of a 2-d vector here (about halfway down the page).

To rotate one point about another, you will generally apply a translation such that the pivot point becomes the origin, apply the rotation, and then translate back, e.g.:
vector2 RotatePointAboutPoint(vector2 p, vector2 pivot, float angle) {    vector2 v = p - pivot;    v = RotateVector(v, angle);    return pivot + v;}
Note that it's usually easier to approach this sort of problem in terms of matrix transforms and transform hierarchies. (Ask if you would like more details on this.)

##### Share on other sites
Let's say you have point X that you want to rotate around point C. The correct mathematical formula in 2D is:

Y.x = [cos(θ) * (X.x - C.x)] - [sin(θ) * (X.y - C.y)] + C.x;
Y.y = [sin(θ) * (X.x - C.x)] + [cos(θ) * (X.y - C.y)] + C.y;

Although if your angle is always 90°, you can replace those sines and cosines with constants (they simplify to ±1 and 0).

EDIT: Typo [grin]

[Edited by - Zipster on August 21, 2008 12:20:17 PM]

##### Share on other sites
Thanks to both of you guys. I hadn't even thought about vector math for some reason. I do like Zipsters solution because it was what I was looking for. Vector transforms would probably be faster but since I'm making a falling blocks ;) for my own personal learning I don't think performance will be much of an issue.

I'll probably use both and play around with them.

##### Share on other sites
After looking I realized that they're both the same thing, Zipster simply put it in one equation and jyk split it up to make it more readable.

You did have one problem in your equation Zipster the Y.y equation should read:

Y.y = [sin(θ) * (X.x - C.x)] + [cos(θ) * (X.y - C.y)] + C.y;

Thanks again for the help guys.

##### Share on other sites
Quote:
 Original post by tehXKnightAfter looking I realized that they're both the same thing, Zipster simply put it in one equation and jyk split it up to make it more readable.You did have one problem in your equation Zipster the Y.y equation should read:Y.y = [sin(θ) * (X.x - C.x)] + [cos(θ) * (X.y - C.y)] + C.y;Thanks again for the help guys.

Doh, that's right I forgot a cosine, stupid copy-paste [headshake]

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 9
• 11
• 15
• 11
• 11
• ### Forum Statistics

• Total Topics
634149
• Total Posts
3015830
×