Function Repository Resource:

# QuaternionToRotationMatrix

Convert a unit quaternion to an equivalent rotation matrix

Contributed by: Jan Mangaldan
 ResourceFunction["QuaternionToRotationMatrix"][w] converts the unit quaternion w into an equivalent 3×3 rotation matrix.

## Details and Options

The argument w should be a numeric Quaternion object, or a scalar that can be converted into one.
If the argument w is not a unit quaternion, ResourceFunction["QuaternionToRotationMatrix"] begins by normalizing it.

## Examples

### Basic Examples (3)

Define a quaternion:

 In[1]:=
 Out[1]=

Generate a rotation matrix from a unit quaternion:

 In[2]:=
 Out[2]=

Verify that the result is a rotation matrix:

 In[3]:=
 Out[3]=

### Scope (4)

An exact quaternion:

 In[4]:=
 Out[4]=

An approximate MachinePrecision quaternion:

 In[5]:=
 Out[5]=

An approximate arbitrary precision quaternion:

 In[6]:=
 Out[6]=

 In[7]:=
 Out[7]=

### Applications (2)

Create a unit quaternion:

 In[8]:=
 Out[8]=

Also define a vector to be rotated:

 In[9]:=
 Out[9]=

Transform the vector using the quaternion representation of a rotation:

 In[10]:=
 Out[10]=

Transform the vector using the rotation matrix representation to get the same result:

 In[11]:=
 Out[11]=

Get the axis-angle representation of a quaternion:

 In[12]:=
 Out[12]=

Recover the original quaternion:

 In[13]:=
 Out[13]=

## Version History

• 1.0.0 – 23 December 2020