# Derive Rigid Transform Matrix from Axes and Origin

I'm trying to derive the matrix of a rigid transform to map between two coordinate spaces. I have the origin and the axis directions of the target coordinate space in terms of the known coordinate space; does anyone know how I can solve for the 4x4 rigid transformation matrix given these?

So, in other words, I have two coordinate spaces, A and B, and I know

Point3D originOfBInA;
Vector3D xAxisOfBInA; // Unit vector
Vector3D yAxisOfBInA; // Unit vector
Vector3D zAxisOfBInA; // Unit vector


And I'm trying to find the 4x4 matrix $\quad$

Matrix4x4 AtoB;

-

Let $e_1, e_2, e_3$ be a basis of coordinate space $A$. Express your given vectors (xAxisOfBInA, etc..) in terms of the basis of A, lets label them as column vectors $v_1, v_2, v_3$.

Then coordinate transform matrix is $C = \pmatrix{v_1 & |& v_2 &|& v_3}$. But since you are shifting the origin, you are doing a 3D affine transform, which can be represented as a 4D linear transform.

Represent coordinates $(x,y,z) \in A$ as $\vec{x} = (x,y,z,1)$. Then the representation of $\vec{x}$ in $B$ is $D\vec{x}$, where $D = \pmatrix{C & x_0 \\ 0 & 1}$, where $x_0$ is the representation of originOfBInA in terms of the basis of $A$.

If this is too abstract, I can work out an example if you'd like.

-
Actually, hold on now, I'm not sure I follow. I understand the change of basis transform C , but the translation component of the affine transform I'm not sure I follow. If $x_0$ is the representation of the origin in B in terms of the basis of A, then $Dx_0 = \vec{0}$, or $Cx_0 + t = \vec{0}$, so $t = -Cx_0$. Doesn't this mean that $D = \pmatrix{C & -Cx_0 \\ 0 & 1}$? – anjruu Dec 6 '12 at 19:21
Look at it this way. Let $\vec{X} = (x,y,z,1)$ and $\vec{x} = (x,y,z)$. Then, $D\vec{X} = C\vec{x} + x_0$ if you remove the extra $1$ coordinate after calculation is done. It looks like what you're saying is that $x_0$ is the origin of A and the zero vector is the origin of B. My statement is mapping the zero vector in A to the origin $x_0$ of B. Does that help at all? – StuartHa Dec 6 '12 at 20:03