[Math] Transforming point between euclidean coordinate systems

coordinate systemseuclidean-geometrygeometry

I have point $P_2(x_2, y_2, z_2)$, which is situated in euclidean coordinate system $xyz$. I want to transform this point to similar coordinate system $x'y'z'$ arbitrarily rotated (three directions are some known vectors) and centered at point $P_1(x_1, y_1, z_1)$ – center relative to system $xyz$. So new coordinates of point $P_2$ would be relative to $(0, 0, 0)$ at center of $x'y'z'$. How can I (easily) do that?
enter image description here

Best Answer

This coordinate transformation consists of a translation followed by a rotation: $(x',y',z')=R(P_2-P_1)$. To construct the rotation matrix $R$, recall that the columns of a transformation matrix are images of the basis vectors. Let $\mathbf u_{x'}$, $\mathbf u_{y'}$ and $\mathbf u_{z'}$ be unit vectors in the original coordinate system that define the new coordinate axis directions. Then the rotation matrix which maps from the rotated coordinates to the original ones, $R^{-1}$ has these vectors as its columns. Since the inverse of a rotation matrix is its transpose, $R$ is the matrix that has these unit vectors for rows.

The transformation $R(P_2-P_1)$ therefore expands to $$\begin{align}x'&=(P_2-P_1)\cdot\mathbf u_{x'} \\ y'&=(P_2-P_1)\cdot\mathbf u_{y'} \\ z'&=(P_2-P_1)\cdot\mathbf u_{z'}\end{align}$$ which says that the new coordinates are the projections of $P_2$ onto the new coordinate axes. This is one of the definitions of coordinates, though, so we could’ve gotten this last set of equations directly from the definition.

Depending on your application, it might be more convenient to package this up into the homogeneous transformation matrix $$\begin{bmatrix}R&-RP_1\\\mathbf 0&1\end{bmatrix}$$ which includes the translation as part of the matrix multiplication.