This is the follow-up question from here: Minimum requirements to uniquely represent a 3D object in space

Assume I have 3 original points in a 3D object (in 3D space) as A1=<xa,ya,za>, A2=<xa,ya,za>, and A3=<xa,ya,za> (assume we have all the requirements mentioned in our previous question). The 3D object is moved and rotated in the 3D space, and the new destination points become B1=<xb,yb,zb>, B2=<xb,yb,zb>, and B3=<xb,yb,zb>.

What is the formula for the transformation matrix? Basically, I need a matrix that if applied to all points of the origin object, I get the displaced object.

  • 1
    $\begingroup$ For near minimal you store a vector for the translation and a quaternion for the rotation, so 7 elems to store. So the matrix is simply the quaternion to rotation matrix + translation. $\endgroup$ Commented Jun 15, 2017 at 20:05
  • $\begingroup$ Yes, that I know. But can you post how that rotation matrix really looks like? The rows and columns. $\endgroup$
    – angel_30
    Commented Jun 15, 2017 at 21:25

1 Answer 1


Skimming the math. Starting with a quaternion $Q=w+\left(x,y,z\right)$ then we can rotate $\mathbf{v}$ by:

$$\mathbf{v}' = Q\mathbf{v}Q^{-1}$$

and if $Q$ is unit magnitude this reduces to:

$$\mathbf{v}' = Q\mathbf{v}Q^*$$

To create a matrix we need to apply the rotation to the basis set to form our three equations:

$$ \mathbf{x} = \left(1,0,0\right) \\ \mathbf{y} = \left(0,1,0\right) \\ \mathbf{z} = \left(0,0,1\right) \\ $$

which expanded and reduced gives:

$$ \mathbf{x}' = Q\mathbf{x}Q^{-1} = \left(1 - 2 \left(y^2+z^2\right), 2\left(xy+wz\right), 2\left(xz-wy\right) \right) \\ \mathbf{y}' = Q\mathbf{y}Q^{-1} = \left(2 \left(xy-wz\right), 1 - 2\left(x^2+z^2\right), 2\left(wx+yz\right) \right) \\ \mathbf{z}' = Q\mathbf{z}Q^{-1} = \left(2 \left(wy+xz\right), 2\left(yz-wx\right), 1 - 2\left(x^2+y^2\right) \right) $$

Sticking to the math convention of column vectors, then we shove the three equations into the first three columns and to add a translation by $\left(t_x,t_y,t_z\right)$ we shove that into the last column giving:

$$ { \left( \begin{array}{ccc} 1 - 2 \left(y^2+z^2\right) & 2\left(xy-wz\right) & 2\left(xz+wy\right) & t_x\\ 2 \left(xy+wz\right) & 1 - 2\left(x^2+z^2\right) & 2\left(wx-yz\right) & t_y \\ 2 \left(wy-xz\right) & 2\left(yz+wx\right) & 1 - 2\left(x^2+y^2\right) & t_z \\ 0 & 0 & 0 & 1 \end{array} \right) } $$

  • 1
    $\begingroup$ It's the conjugate which is the same as inverse when unit magnitude. $\endgroup$ Commented Jun 16, 2017 at 16:12
  • 1
    $\begingroup$ There was a seemly deleted comment along the lines of "not useful to have the matrix". This is true, you work with the rotation translation pair..and when transforming points you don't actually create a matrix (don't need to at least). The matrix is to show the sub-expressions that need to be computed. And this is assuming that the average number of points is (somewhere) greater than one. Otherwise you're better off performing the rotation directly from the quaternion expression. $\endgroup$ Commented Jun 17, 2017 at 18:15
  • 1
    $\begingroup$ It's more efficient to convert to a matrix instead of using quaternion directly if you transform more than one vector with the same quaternion. Also for more compact representation you don't need to store w since you are dealing with unit quaternions: w=sqrt(1-x^2-y^2-z^2). $\endgroup$
    – JarkkoL
    Commented Jun 18, 2017 at 4:25
  • 1
    $\begingroup$ I was attempting to say the matrix doesn't need to be stored..it's on the stack. Dropping the scalar doesn't work very well: marc-b-reynolds.github.io/quaternions/2017/05/02/… $\endgroup$ Commented Jun 18, 2017 at 7:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.