Ok, i know this might have been asked, but the search is giving me errors.
Anyway, i need to figure out this equation. I have a point in 2D space, say pX and pY, and they need to rotate in a circle around the origin, or oX and oY, at a set radius. I want to make them rotate one degree every loop iteration, counterclockwise. I know it has something to do with sine and cosine, but i cant find it anywhere and kind of didnt pay attention that day in math class :P
Thanks for your help...
Remember polar coordinates from class? This is the formula for transforming a point in a polar system into the usual cartesian coordinates, where (x, y) is the 2d coordinates and (r, a) is the point's radius/angle.
x = r*cos a y = r*sin a
It turns out that rotating a point in a polar system is a lot more intuitive than doing the same to normal 2d point. All you have to do is add the desired rotation, b, to the original angle a. Lets apply this to the previous equation to get the cartesian coordinates for the rotated point.
x' = r*cos(a + b) y' = r*sin(a + b)
By using the angle sum relations for sine/cosine we can rewrite the previous equations.
x' = r*(cos a*cos b - sin a*sin b) y' = r*(sin a*cos b + cos a*sin b)
x' = (r*cos a)*cos b - (r*sin a)*sin b y' = (r*sin a)*cos b + (r*cos a)*sin b
Since r*cos/sin a are the original expressions for projecting the point without any rotation we can subsitute them for x/y.
x' = x*cos b - y*sin b y' = y*cos b + x*sin b
x' = x*cos b - y*sin b y' = x*sin b + y*cos b
And that's all there is too it. To rotate around a point other than origo you'll have to subtract the desired point from (x, y), perform the rotation and add it back again onto the final (x', y') point.
[Edited by - doynax on December 3, 2004 6:23:08 PM]