Get the 4-d rotation matrix given two planes There are two 2-d planes in 4-d space (both passing through the origin). They intersect in a line. We are given the coordinates of three points for the first plane (a $3 \times 4$ matrix, $V_1$ where each row is one of the three points) and the coordinates of three points for the second one ($V_2$).
Imagine translating both planes so the origin passes through both of them. Now, they will also have an intersecting line (even if they didn't before).
I'd like to rotate the second plane with respect to the first along the common line between them. This will involve shifting the origin somewhere along the common line and then the rotation can be represented by a rotation matrix ($R$, a $4 \times 4$ matrix). How do I get this rotation matrix?
 A: Since the second plane intersects with the first in a line, then we can parameterize the two planes as follows
$ p = r \ v_1 + s \ v_2 $   (first plane)
$ q = t \ v_1 + u \ v_3 $   (second plane)
where $v_1, v_2, v_3 \in \mathbb{R}^4$, and $r, s, t, u \in \mathbb{R}$ are scalars.  Here $v_1$ is the vector along the common line between the two planes.
Since we want to map the second plane into the first using a rotation matrix $R$, we can assume that $v_2$ and $v_3$ are unit vectors orthogonal to $v_1$ (also a unit vector), if not, then we can use Gram-Schmidt orthogonalization to orthogonalize them.
Now we only need to rotate $v_3$ into $v_2$ and this will rotate the second plane into the first plane.  The rotation should leave $v_1$ unaffected.
First, generate a basis for the orthogonal complement of $\text{Span}(v_3, v_2) $, i.e. solve the linear system
$ \begin{bmatrix} v_3^T \\ v_2^T \end{bmatrix} s = 0 $
Let $s_1, s_2$ be a basis for this orthogonal complement.  Now we will apply Gram-Schmidt orthogonalization to the vectors $[v_3, v_2, s_1, s_2]$ to obtain the orthogonal matrix $Y = [y_1, y_2, y_3, y_4]$, with $y_1 = v_3$
So now matrix $Y$ defines an orthonormal basis for $\mathbb{R}^4$.  The coordinate of any vector $x \in \mathbb{R}^4$ with respect to this basis is given by
$ z = Y^T x  $
This means that the coordinate of $v_3$ with respect to the $Y$ basis is
$z_3 =[1, 0, 0, 0]^T $
And similarly, the coordinate of $v_2$ with respect to the $Y$ basis is
$z_2 = [ \cos(\theta), \sin(\theta), 0, 0]^T $
where $\theta$ is the angle between $v_3$ and $v_2$.  To rotate $z_3$ into $z_2$, we will apply the rotation matrix $R'$ with respect to the $Y$ basis
$ R' = \begin{bmatrix} \cos(\theta) && - \sin(\theta) && 0 && 0 \\
\sin(\theta) && \cos(\theta) && 0 && 0 \\
0 && 0 && 1 && 0 \\
0 && 0 && 0 && 1 \end{bmatrix} $
To get the rotation matrix in the standard basis, we note that
$ x' = Y \ z' = Y \ R' \ z = Y \ R' \ Y^T \ x $
Therefore, the required rotation matrix is
$ R = Y \ R' \ Y^T $
Note that since $v_1$ is orthogonal to both $v_3$ and $v_2$, it will not be affected by this rotation, therefore, the image of any point on the second plane
$ q = t \ v_1 + u \ v_3 $
will be
$ q' = R q = R (t \ v_1 + u \ v_3) = t R \ v_1 + u R \ v_3 = t v_1 + u \ v_2 $
which means that the image $q'$ lies in the first plane.
A: Find the normal vectors $U$ and $V$ of the two planes. Let $\theta$ be the angle between $U$ and $V$, and let $W$ be their cross product. The rotation you’re looking for is a rotation around $W$ by the angle $\theta$. If you want it in matrix form, use Rodrigues’ formula.
