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

<p>$$\mathbf{v}' = Q\mathbf{v}Q^{-1}$$</p>

<p>and if $Q$ is unit magnitude this reduces to:</p>

<p>$$\mathbf{v}' = Q\mathbf{v}Q^*$$</p>

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

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

<p>which expanded and reduced gives:</p>

<p>$$
\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)
$$</p>

<p>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:</p>

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

CC BY-SA 3.0
2017-06-16T16:12:08.617Z
It's the conjugate which is the same as inverse when unit magnitude.
MB Reynolds
CC BY-SA 3.0
2017-06-17T18:15:48.150Z
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.
MB Reynolds
CC BY-SA 3.0
2017-06-18T04:25:12.007Z
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).
JarkkoL
CC BY-SA 3.0
2017-06-18T07:13:17.563Z
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: http://marc-b-reynolds.github.io/quaternions/2017/05/02/QuatQuantPart1.html
MB Reynolds
CC BY-SA 3.0
2017-06-16T12:05:35.587Z
2017-06-16T12:05:35.587Z
MB Reynolds
<p>This is the follow-up question from here: <a href="https://computergraphics.stackexchange.com/questions/5222/">Minimum requirements to uniquely represent a 3D object in space</a></p>

<p>Assume I have 3 original points in a 3D object (in 3D space) as <code>A1=&lt;xa,ya,za&gt;</code>, <code>A2=&lt;xa,ya,za&gt;</code>, and <code>A3=&lt;xa,ya,za&gt;</code> (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 <code>B1=&lt;xb,yb,zb&gt;</code>, <code>B2=&lt;xb,yb,zb&gt;</code>, and <code>B3=&lt;xb,yb,zb&gt;</code>. </p>

<p>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.</p>

CC BY-SA 3.0
2017-06-15T20:05:24.093Z
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.
MB Reynolds
CC BY-SA 3.0
2017-06-15T21:25:25.903Z
Yes, that I know. But can you post how that rotation matrix really looks like? The rows and columns.
angel_30
<3d><transformations><matrix><normal-mapping><mapping>
Rotation matrix for a 3D object in space
angel_30
# Rotation matrix for a 3D object in space

(Asked by: username_0 on 2017-06-12)

This is the follow-up question from here: [Minimum requirements to uniquely represent a 3D object in space](https://computergraphics.stackexchange.com/questions/5222/)

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.

**Tags:** 3d, transformations, matrix, normal-mapping, mapping

> **Comments:**
> **username_1**: 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.  
> **username_0**: Yes, that I know. But can you post how that rotation matrix really looks like? The rows and columns.  

---

## 1 answers

### Answer by username_1 on 2017-06-16. Score: 2 | Accepted answer

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)
}
$$

> **Comments:**
> **username_1**: It's the conjugate which is the same as inverse when unit magnitude.  
> **username_1**: 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.  
> **username_2**: 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).  
> **username_1**: 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: http://marc-b-username_1.github.io/quaternions/2017/05/02/QuatQuantPart1.html  

---

