3

There are Two Points A and B. The linear distance between the points is R. I have the coordinates of both points given as X and Y values, and these points can be anywhare in on the 2D plane.

I need to rotate Point A around point B for a given angle (for example 12.56 deg) and get the X and Y coordinates of the new location. The rotation is clockwise.

How can these new X and Y coordinates be calculated?

Thanks!

3 Answers3

6

Hint: If you know how to rotate about the origin, you have to calculate (using pseudo code notation) $$(X,Y) = (B_X, B_Y) + \mathrm{rotate\_origin}(A_X-B_X, A_Y-B_Y)$$

Edit: For 2D rotations you use http://en.wikipedia.org/wiki/Rotation_matrix#In_two_dimensions and remember to convert your angle to radians before using $\cos, \sin.$ $$X = B_X + (A_X-B_X)\cos\phi - (A_Y-B_Y)\sin \phi $$ $$Y = B_Y + (A_X-B_X)\sin\phi + (A_Y-B_Y)\cos \phi $$

gammatester
  • 18,827
3

Hint: For rotating a position vector $\vec r$ to $\vec r'$ about the origin by an angle $\theta$, the transformation is given by the matrix $R$:

$$\vec r' =R\vec r=\left(\begin{matrix} \sin\theta & \cos\theta \\ \cos\theta & -\sin\theta \end{matrix}\right)\vec r$$

In your application, the vector $\vec r = \vec a- \vec b$

danimal
  • 1,889
0

The rotated coordinates are $x'=x \cos(\theta)-y \sin(\theta)$ and $y'=x \sin(\theta)+y \cos(\theta)$
although you'll need to convert you degrees angles to radians first by multiplying by the "degrees to radians" constant first: $\theta=a \frac \pi{360}$
Incase your programming language (you said you were a programmer, i am one too for your notice) doesn't support $\cos$ and $\sin$ by default you can use a different solution.

  • No one else used this formula, so it's useful, plus no need for matrices! –  Jun 22 '23 at 11:29