Rotate 2d coordinates

194 Views Asked by At

I haven't touched Maths in quite a long time haha. So I have 3 coordinates, (-1,0), (0,0 this being the pivot/origin), (1,0). I would like to rotate it 90 degrees. Any idea how?

This is just a simple example.

2

There are 2 best solutions below

1
On BEST ANSWER

If you want to rotate around the origin, you could follow these rules:

90º rotation: (x, y) → (-y, x).

180º rotation: (x, y) → (-x, -y).

270º rotation: (x, y) → (y, -x).

For example:

90º Rotation

A(6, 1) → A′(-1, 6)

B(7, 2) → B′(-2, 7)

180º Rotation

A(6, 1) → A′(-6, -1)

B(7, 2) → B′(-7, -2)

270º Rotation

A(6, 1) → A′(1, -6)

B(7, 2) → B′(2, -7)

3
On

You can do this with vectors.

  1. First build vectors with the 2D coordinates.

  2. You can now move to point you want to rotate around (by vector subtraction)

  3. then rotate it by multiplying it by a rotation matrix. A rotation matrix for 90 degrees would be $\left[\begin{array}{rr}0&-1\\1&0\end{array}\right]$ or $\left[\begin{array}{rr}0&1\\-1&0\end{array}\right]$ depending on clockwise or anti-clockwise.

  4. then move back by matrix addition

In Matlab or Gnu Octave to rotate (2,1) 90 degrees around (1,1) would be this line of code:

[0,-1;1,0]*([2;1]-[1;1])+[1;1]

the answer is (1,2)

if you want to rotate also point (1,2) 90 degrees you stuff it into the vector so it becomes a matrix

[0,-1;1,0]*([[2;1],[1;2]]-[1;1])+[1;1]

This only works if you have automatic broadcasting on in Octave and a relatively new version of Matlab. Formally what you need to do is to do a Kronecker product ($\otimes$) of the (1,1) vector with a vector of ones to become the same size as the matrix of points you want to rotate.

For example $({\bf p_1}\otimes [1,1,1,1]) = [{\bf p_1, p_1, p_1, p_1}]$

Would be suitable for the operations to make sense if we rotated 4 different vectors around $\bf p_1$.