Geometry - Calculate rotation matrix from sets of 3 vectors

48 Views Asked by At

I have a set of 3 vectors from coordinate system O1

P1_O1 = [4,0,2] // Point 1 from O1
P2_O1 = [4,2,2]
P3_O1 = [4,0,0]

P1P2_O1 = P2_O1 - P1_O1 // Vector P1P2 from O1
P1P3_O1 = P3_O1 - P1_O1
P2P3_O1 = P3_O1 - P2_O1

and the same vectors from coordinate system O2

P1_O2 = [2,0,0] // Point 1 from O2
P2_O2 = [2,2,0]
P3_O2 = [0,0,0]

P1P2_O2 = P2_O2 - P1_O2 // Vector P1P2 from O2
P1P3_O2 = P3_O2 - P1_O2
P2P3_O2 = P3_O2 - P2_O2

I am trying to calculate rotation matrix by this formula

PiPj_O1 = R0 * (PiPj_O2)

or expressed in another way

[P1P2_O1, P1P3_O1, P2P3_O1] = R0 * [P1P2_O2, P1P3_O2, P2P3_O2]

So that

R0 = [P1P2_O1, P1P3_O1, P2P3_O1] * [P1P2_O2, P1P3_O2, P2P3_O2]^-1

The Rotation Matrix I should get is:

R0 = [0 0 -1, 0 1 0, 1 0 0]

Coordinate system O1 is rotated -90deg in Y axis with regard coordinate system O2, and translated (x = 4, y = 0, z = 0)

I am doing this calculations but I am not able to get the correct rotation matrix. How could I address it?

example

1

There are 1 best solutions below

0
On BEST ANSWER

Let $P_i$'s be the coordinates of the three points with respect to the red frame, and $P_i'$ be the coordinates of the three points with respect to the green frame.

If $X_i$ is the coordinate vector in the world reference frame, then

$ X_i = O_1 + R_1 P_i = O_2 + R_2 P_i' $

In this problem, we know $O_1 = \mathbf{0}$ and $O_2 = \begin{bmatrix} 4 \\ 0 \\ 0 \end{bmatrix} $

We also know that $R_1 = I_3$ (the identity matrix). Hence,

$ X_i = P_i = O_2 + R_2 P_i' $

Therefore,

$ P_i - O_2 = R_2 P_i' $

In order to determine $R_2$, we put the above equation in matrix-matrix form as follows

$ [ P_1 - O_2, P_2 - O_2, P_3 - O_2 ] = R_2 [P_1', P_2', P_3'] $

The problem here is that $P_3'$ is at the origin, so we cannot invert the above equation to determine R_2.

However, there is a way around this. First take the difference between the three columns to obtain

$ [P_2 - P_1 , P_3 - P_1, P_3 - P_2 ] = R_2 [ P_2' - P_1' , P_3' - P_1' , P_3' - P_2' ] $

Note that the length of $P_i - P_j$ is equal to the length $P_i' - P_j'$

Again this won't help because the columns of both matrices on either side of the equation are linearly dependent.

The way out of this dilemma, is to use the cross product. So let

$ V = (P_2 - P_1) \times (P_3 - P_1) $

And

$V' = (P_2' - P_1') \times (P_3' - P_1') $

Now replace the above matrix equation with the following one

$ [P_2 - P_1 , P_3 - P_1, V ] = R_2 [ P_2' - P_1' , P_3' - P_1' , V' ] $

From the figure, we have

$P_2 - P_1 = (0,2,0) , P_3 - P_1 = (0, 0, -2) $

$P_2' - P_1' = (0,2,0) , P_3' - P_1' = (-2, 0, 0) $

Therefore,

$ V = (0,2,0) \times (0, 0, -2) = ( -4 , 0, 0 ) $

$ V' = (0, 2, 0) \times (-2, 0, 0) = (0 , 0, 4 ) $

Now we have

$ \begin{bmatrix} 0 && 0 && -4 \\ 2 && 0 && 0 \\ 0 && -2 && 0 \end{bmatrix} = R_2 \begin{bmatrix} 0 && -2 && 0 \\ 2 && 0 && 0 \\ 0 && 0 && 4 \end{bmatrix} $

From this, it follows that

$R_2 = \begin{bmatrix} 0 && 0 && -1 \\ 0 && 1 && 0 \\ 1 && 0 && 0 \end{bmatrix}$