Function Repository Resource:

# RotationMatrixToQuaternion

Convert a rotation matrix to an equivalent unit quaternion

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

## Details and Options

ResourceFunction["RotationMatrixToQuaternion"] works for exact as well as numerical real rotation matrices.
ResourceFunction["RotationMatrixToQuaternion"] returns results as ResourceFunction[“Quaternion”] objects.

## Examples

### Basic Examples (2)

Generate a rotation matrix:

 In[1]:=
 Out[1]=

Convert to quaternion form:

 In[2]:=
 Out[2]=

### Scope (3)

A real matrix:

 In[3]:=
 Out[3]=

Convert to quaternion form:

 In[4]:=
 Out[4]=

An approximate MachinePrecision matrix:

 In[5]:=
 Out[5]=
 In[6]:=
 Out[6]=

An approximate arbitrary precision matrix:

 In[7]:=
 Out[7]=
 In[8]:=
 Out[8]=

### Applications (4)

Create a rotation matrix:

 In[9]:=
 Out[9]=

Also define a vector to be rotated:

 In[10]:=
 Out[10]=

Transform the vector using the rotation matrix representation:

 In[11]:=
 Out[11]=

Transform the vector using the quaternion representation of a rotation to get the same result:

 In[12]:=
 Out[12]=

Generate a matrix from a given set of Euler angles:

 In[13]:=
 Out[13]=

Convert to its quaternion representation:

 In[14]:=
 Out[14]=

Generate a matrix from a given set of roll-pitch-yaw angles:

 In[15]:=
 Out[15]=

Convert to its quaternion representation:

 In[16]:=
 Out[16]=

Generate a random rotation matrix:

 In[17]:=
 Out[17]=

Convert to its quaternion representation:

 In[18]:=
 Out[18]=

## Version History

• 1.0.0 – 23 December 2020