How do I find the rotation matrix starting from 2 plane equation?

82 Views Asked by At

In my project I have 2 plane equations in general form 'ax+by+cz+d=0' that are '-0.0x+0.0y+1.0z-867=0' and '-0.48x+0.0y+0.88z-770=0'. How can I find the rotation matrix that brings a point from the first plane to the second?

1

There are 1 best solutions below

2
On BEST ANSWER

The equation of the first plane is

$ n_1^T r_1 + d_1 = 0 $

and of the second plane is

$ n_2^T r_2 + d_2 = 0 $

Now we define the affine transformation

$ T(r) = R r + v $

and we want the image of $r_1$ to lie on the second plane

$ T(r_1) = R r_1 + v $

Since this is to lie on the second plane, then

$ n_2^T R r_1 + n_2^T v + d_2 = 0 $

But $r_1$ satisfies

$ n_1^T r_1 + d_1 = 0 $

Therefore, we must have

$ n_1^T = n_2^T R $ , i.e. $ n_1 = R^T n_2 $, which implies that

$n_2 = R n_1 $

And in addition, we require that

$d_1 = n_2^T v + d_2 $

i.e.

$ n_2^T v = d_1 - d_2 $

For the given numerical example

$ n_1 = [0, 0, 1] $

$ n_2 = [-0.4788, 0, 0.8779] $ (after normalization)

The matrix $R$ that take $n_1$ to $n_2$ is not unique, but the most obvious choice for the axis of rotation is $n_1 \times n_2$

$n_1 \times n_2 = [0, -0.4788, 0] $

So that the axis is

$ a = [0, -1, 0] $ after normalization

While the angle of rotation is $ \theta = \sin^{-1}( \| n_1 \times n_2 \| ) = \sin^{-1} (0.4788) = 28.6^\circ $

We have to check that this is the correct angle using the $\cos$ function and the dot product. Since the dot product is positive, this is indeed the correct angle.

Now the matrix $R$ is a rotation about the negative $y$ axis by $\theta$ which is equivalent to a rotation about the positive $y$ by $(-\theta)$. The formula for the rotation matrix about the (positive) $y$ axis by an angle $\phi$ is

$ R = \begin{bmatrix} \cos \phi && 0 && \sin \phi \\ 0 && 1 && 0 \\ -\sin \phi && 0 && \cos \phi \end{bmatrix} $

Substituting $\phi = - \theta = - 28.6^\circ $ gives us the rotation matrix

$ R = \begin{bmatrix} 0.8779 && 0 && -0.4787 \\ 0 && 1 && 0 \\ 0.4787 && 0 && 0.8779 \end{bmatrix} $

Now the vector $v$ satisfies

$ [-0.4788, 0, 0.8779] v = -867 + 768.15 = -98.84 $

So a possible $v = [ 206.4 , 0, 0 ] $

To verify the above calculations, select a point on the first plane, for example $r_1 = [1, 2, 867]^T $, apply the transformation, then

$ r_2 = R r_1 + v = [-207.755, 2 , 761.618]^T$

Plug this into the equation of the second plane

$ -0.48(-207.755) + 0(2) + 0.88 (761.618) = 769.95 $

which away from $770$ by $0.05$, and this is due to round-off errors. So, $r_2$ lies on the second plane.

EDIT:

Alternatively, you can find the rotation matrix as a composite of rotation about the $x$ axis , then $y$ axis, then $z$ axis. Although only $2$ rotations about these axes are necessary, we don't know which ones beforehand. The rotation matrix about the $x$ axis is given by

$ R_x = \begin{bmatrix} 1 && 0 && 0 \\ 0 && c_1 && -s_1 \\ 0 && s_1 && c_1 \end{bmatrix} $

where $c_1 = \cos \phi_1 $ and $s_1 = \sin \phi_1 $ where $\phi_1$ is the angle of rotation about the $x$ axis.

Similarly, we have

$R_y = \begin{bmatrix} c_2 && 0 && s_2 \\ 0 && 1 && 0 \\ -s_2 && 0 && c_2 \end{bmatrix} $

where $c_2 = \cos \phi_2 $ and $ s_2 = \sin \phi_2 $ where $\phi_2 $ is the angle of rotation about the $y$ axis.

And finally,

$R_z = \begin{bmatrix} c_3 && -s_3 && 0 \\ s_3 && c_3 && 0 \\ 0 && 0 && 1 \end{bmatrix}$

where $c_3 = \cos \phi_3 $ and $s_3 = \sin \phi_3 $ where $\phi_3$ is the angle of rotation about the $z$ axis.

The overall rotation matrix is

$ R = R_z R_y R_x = \begin{bmatrix} c_2 c_3 && s_1 s_2 c_3 - c_1 s_3 && c_1 s_2 c_3 + s_1 s_3 \\ c_2 s_3 && s_1 s_2 s_3 + c_1 c_3 && c_1 s_2 s_3 - s_1 c_3 \\ -s_2 && s_1 c_2 && c_1 c_2 \end{bmatrix} $

And we want to find $\phi_1, \phi_2, \phi_3$ such that

$ R n_1 = n_2 $

This leads to the following system of equations

$n_{1x} c_2 c_3 + n_{1y} (s_1 s_2 c_3 - c_1 s_3) + n_{1z} (c_1 s_2 c_3 + s_1 s_3) = n_{2x}$

$n_{1x} c_2 s_3 + n_{1y} (s_1 s_2 s_3 + c_1 c_3) + n_{1z} (c_1 s_2 s_3 - s_1 c_3) = n_{2y}$

$n_{1x} (-s_2) + n_{1y} (s_1 c_2) + n_{1z} (c_1 c_2) = n_{2z}$

Suppose we take $\phi_3 = 0$ then $c_3 = 1 , \ s_3 = 0 $ and the above equations becomes

$n_{1x} c_2 + n_{1y} (s_1 s_2 ) + n_{1z} (c_1 s_2 ) = n_{2x}$

$n_{1x} (0) + n_{1y} ( c_1 ) + n_{1z} (- s_1) = n_{2y}$

$n_{1x} (-s_2) + n_{1y} (s_1 c_2) + n_{1z} (c_1 c_2) = n_{2z}$

The second equation involves only $c_1$ and $s_1$ and can be solved readily for $\phi_1$. The solution is

$ \phi_1 = \psi_1 \pm \cos^{-1} \bigg( \dfrac{n_{2y}}{\sqrt{ {n_{1y}}^2 + {n_{1z}}^2 }} \bigg) $

where $\cos(\psi_1) = \dfrac{n_{1y}}{\sqrt{{n_{1y}}^2 + {n_{1z}}^2 } } $ and $\sin(\psi_1) = \dfrac{-n_{1z}}{\sqrt{{n_{1y}}^2 + {n_{1z}}^2 } }$

That is, $\psi_1 = \text{atan2}( n_{1y} , -n_{1z} ) $

Both values of $\phi_1$ are acceptable. Now that we have $\phi_1$, we are left with the first and third equations, which can be looked upon as two linear equations in $c_2 $ and $s_2$, and can be solved explicitly for these values.

Now we have all the cosines and sines of all the three angles, so the three rotation matrices about $x$ , $y$, $z$ are explicitly known.

The above will work as long the second equation above has a solution. However, if

$ n_{2y}^2 \gt n_{1y}^2 + n_{1z}^2 $

Then the second equation doesn't have a solution. In this case, we can take $\phi_1 = 0$, then $c_1 = 1 , s_1 = 0 $, and this would change the system of equations into

$n_{1x} c_2 c_3 + n_{1y} (- s_3) + n_{1z} (s_2 c_3 ) = n_{2x}$

$n_{1x} c_2 s_3 + n_{1y} ( c_3) + n_{1z} (s_2 s_3 ) = n_{2y}$

$n_{1x} (-s_2) + n_{1y} (0) + n_{1z} ( c_2) = n_{2z}$

Here the third equation involves $\phi_2$ only, and similar to the above can be readily solved for $\phi_2$, using

$ \phi_2 = \psi_2 \pm \cos^{-1} \bigg( \dfrac{ n_{2z} }{\sqrt{ {n_{1x}}^2 + {n_{1z}}^2 } } \bigg) $

where $\psi_2 = \text{atan2}( n_{1z} , - n_{1x} ) $

Now that we have $c_2 $ and $s_2$ we substitute that into the first two equations and solve them for $c_3 $ and $s_3 $.