# rotating 2D coordinates

I've tried googling this, but I always end up somewhere that just says it's easy.

Anyhow, I have a coordinate system, where I need to rotate a bunch of points. It's all 2D. Coordinates varies and so does the angles, but the point to rotate around, is always 0,0.

I've look a bit at this post, but I haven't really been able to make it work. http://stackoverflow.com/questions/2259476/rotating-a-point-about-another-point-2d

It mentions subtracting the pivot point, but should I subtract the distance to the pivot point? Since my pivot point is $(0,0)$ it sounds too easy, to just subtract 0 (and also doesn't give me the results I expect).

As an example, I have a point in $(2328.30755138590, 1653.74059364716)$ (very accurate, I know). I need to rotate it $5.50540590872993$ degrees around $(0,0)$.

I would expect it to end in 2339.68319170805, 1878.18099075262(based on a rotation in my CAD software) but I don't really see how I can get it to do that.

Actually, I need to rotate it around $(0, 1884.25802838571)$. Sorry. I have gotten some coordinate systems mixed.

-
Please give a specific example of a situation, where you think the formula gives you a wrong result. Then it will be easier to correct misunderstandings. And, "NO!", you are supposed to subtract the pivot as a vector. How would you subtract a distance from a point anyway? They are incompatible data types. –  Jyrki Lahtonen Sep 13 '12 at 10:33
I am sorry, if I am not being clear. I am asking here because my math skills are horrible. When you say subtract the pivot point as vector, exactly what do you mean? The vector between 0,0 and my point? –  Nicolai Sep 13 '12 at 10:36
Added an example. –  Nicolai Sep 13 '12 at 10:42
check this out –  Santosh Linkha Sep 13 '12 at 10:53

Let's say you want to rotate a point $P = (a, b)$ w.r.t. to point $Q = (c, d)$ by angle $\theta_0$.

You need to first calculate the co-ordinate of point $P$ taking $Q$ as origin, which will be $(a-c, b-d)$.

Convert the representation of P from cartesian co-ordinate system to polar co-ordinate system. Now the polar co-ordinates of P(taking Q as origin) will be

$$(\sqrt{{(a-c)^2}+(b-d)^2}, sin^{-1}\frac{c-d}{\sqrt{{(a-c)^2}+(b-d)^2} })$$

All you have to do now is to incerase the angle by $\theta_0$. Lastly convert the polar co-odinate back to cartesian co-ordinate using this $(r, \theta)$ ~ $(r\sin\theta, r\cos\theta)$.

But note that your co-ordinates are taking poinit Q as origin. To find the co-ordinate w.r.t. to the real origin, just add $c$ and $d$ to the x and y co-ordinates respectively.

Note- To rotate a point $(a,b)$ in cartesian co-ordinate by angle $\phi$ you just need to multiply matrix $\left[ \begin{array}{ c c } \cos\phi & -\sin\phi \\ \sin\phi & \cos \phi \end{array} \right]$and $\left[ \begin{array}{ c c } a \\ b \end{array} \right]$, hecne you can apply this matrix multiplication to $\left[ \begin{array}{ c c } a-c \\ b-d \end{array} \right]$ and then add $c$ and $d$ to the $x$ and $y$ co-ordinate.

-