<p>It's not true to say quaternions don't have a rotation matrix. They are both ways of completely describing a rotation in 3D, so they are freely convertible. Each quaternion corresponds to exactly one rotation matrix, and each rotation matrix corresponds to one quaternion and its negative. Quaternions are just more compact and easier to interpolate.</p>

<p>To work out the rotation matrix for a quaternion, you need to take the effect of the quaternion, <span class="math-container">$q = (w, x, y, z) = (w, \textbf{v}) $</span> on some point <span class="math-container">$\textbf{p}$</span>, that is, <span class="math-container">$(w, \textbf{v}) * (0, \textbf{p}) * (w, \textbf{-v}) $</span>, and express this formula as a matrix operating on <span class="math-container">$\textbf{p}$</span>.</p>

<p>Multiplying out using the rules of quaternions gives us <span class="math-container">$(w^2 - \textbf{v.v})\textbf{p} + 2( w\textbf{v}\times \textbf{p} + \textbf{(v.p)v})  $</span></p>

<p>This can be rearranged into 3 matrix terms - the first part is just a constant value down the diagonal, the second part with the cross product has values everywhere <em>except</em> the diagonal, and the third one is simply <span class="math-container">$\textbf{v}_m *  \textbf{v}_n $</span> for rows m and columns n.</p>

<p>Adding these 3 matrices together gives you </p>

<p><span class="math-container">$\begin{bmatrix} 1-2(y^2+z^2) &amp;2(xy-zw) &amp; 2(xz+yw)\\2(xy + zw)&amp;1-2(x^2+z^2) &amp; 2(yz-xw)\\2(xz-yw) &amp; 2(yz + xw) &amp; 1 - 2(x^2+y^2)\end{bmatrix}$</span></p>

<p>which is the conversion you need.</p>

<p>In your particular use case, though, you are just doing a simple rotate-x through 90 degrees, which simplifies things a lot. Remember a quaternion is <span class="math-container">$ ( cos(\theta/ 2) , sin(\theta/ 2)\textbf{a})$</span>   where <span class="math-container">$\textbf{a}$</span>  is your normalized axis of rotation. So the quaternion representing ±90 degrees rotation around x will be <span class="math-container">$( \frac{1}{\sqrt{2}},±\frac{1}{\sqrt{2}},0,0)$</span></p>

CC BY-SA 4.0
2018-11-08T00:44:36.920Z
"*Quaternions are just more compact and easier to interpolate.*" And easier to re-orthonormalize after applying successive rotations.
Nicol Bolas
CC BY-SA 4.0
2018-11-08T11:01:52.973Z
@NicolBolas or more accurately they are never not orthogonal. They only need renormalization which you can often delay for quite a bit. Or you can embrace the length as a uniform scaling factor, though you would need to adjust the matrix a bit replacing the 1 terms with the squared length of the quaternion.
ratchet freak
CC BY-SA 4.0
2018-11-08T00:40:51.257Z
2018-11-08T00:40:51.257Z
russ
<p>I have to load a mesh in Blender (which uses <code>Z</code> and <code>Y</code> as <em>up</em> and <em>forward</em> axes), modify it and export it (with setting <em>up</em> and <em>forward</em> axes to <code>Y</code> and <code>-Z</code>) and import it into another software which uses a coordinate system with <code>Y</code> up and <code>-Z</code> forward. Later on I export the mesh from this software and import it in Blender for rendering. Since I wanted to get the same rotation in the other software that I get in Blender, I changed the rotation matrix of the other software from Identity to the following:</p>

<pre><code>[1.0, 0.0, 0.0;
0.0, 0.0, -1.0;
0.0, 1.0, 0.0]
</code></pre>

<p>Now I get the same exact rotation in that software that I get in Blender when using Euler angles. However, I have to actually use Quaternions and I realized that Quaternions do not have a rotation matrix. I wonder, what is the equivalent version of rotation matrix for Quaternions? Also, how can I change that equivalent-rotation-matrix of Quaternions so that I get the same rotation that I get in Blender?</p>

CC BY-SA 4.0
2018-11-07T23:36:43.183Z
"*I realized that Quaternions do not have a rotation matrix*" ... what? A quaternion and a rotation matrix are ways to define an orientation (relative to another orientation). You can interconvert between them, with a 2:1 mapping (a quaternion and its negation yield the same rotation matrix). So where are you getting this from?
Nicol Bolas
CC BY-SA 4.0
2018-11-08T00:23:46.920Z
Sorry my bad. I'm pretty bad with rotation stuff and I'm totally new to Quaternions. Could you please help me get answer to my question?
Amir
CC BY-SA 4.0
2018-11-14T01:12:00.990Z
The answer by russ is correct. Unfortunately, if you are unfamiliar with quaternions you will not be able to understand it. I suggest [3Blue1Brown videos](https://www.3blue1brown.com/videos/) as a visual introduction to the topic.
vgs
CC BY-SA 4.0
2018-11-22T09:46:48.150Z
Plus one for 3blue1brown, it's a great resource :) Also check out http://acko.net/blog/animate-your-way-to-glory-pt2/ for a good interactive explanation (the section called 'Blowing Up The Death Star')
russ
<3d><transformations><mathematics><geometry>
What is the equivalent of rotation matrix in Euler angle space for Quaternions?
Amir
# What is the equivalent of rotation matrix in Euler angle space for Quaternions?

(Asked by: username_0 on 2018-11-07)

I have to load a mesh in Blender (which uses `Z` and `Y` as *up* and *forward* axes), modify it and export it (with setting *up* and *forward* axes to `Y` and `-Z`) and import it into another software which uses a coordinate system with `Y` up and `-Z` forward. Later on I export the mesh from this software and import it in Blender for rendering. Since I wanted to get the same rotation in the other software that I get in Blender, I changed the rotation matrix of the other software from Identity to the following:

```
[1.0, 0.0, 0.0;
0.0, 0.0, -1.0;
0.0, 1.0, 0.0]

```

Now I get the same exact rotation in that software that I get in Blender when using Euler angles. However, I have to actually use Quaternions and I realized that Quaternions do not have a rotation matrix. I wonder, what is the equivalent version of rotation matrix for Quaternions? Also, how can I change that equivalent-rotation-matrix of Quaternions so that I get the same rotation that I get in Blender?

**Tags:** 3d, transformations, mathematics, geometry

> **Comments:**
> **username_1**: "*I realized that Quaternions do not have a rotation matrix*" ... what? A quaternion and a rotation matrix are ways to define an orientation (relative to another orientation). You can interconvert between them, with a 2:1 mapping (a quaternion and its negation yield the same rotation matrix). So where are you getting this from?  
> **username_0**: Sorry my bad. I'm pretty bad with rotation stuff and I'm totally new to Quaternions. Could you please help me get answer to my question?  
> **username_2**: The answer by username_3 is correct. Unfortunately, if you are unfamiliar with quaternions you will not be able to understand it. I suggest [3Blue1Brown videos](https://www.3blue1brown.com/videos/) as a visual introduction to the topic.  
> **username_3**: Plus one for 3blue1brown, it's a great resource :) Also check out http://acko.net/blog/animate-your-way-to-glory-pt2/ for a good interactive explanation (the section called 'Blowing Up The Death Star')  

---

## 1 answers

### Answer by username_3 on 2018-11-08. Score: 2 | Accepted answer

It's not true to say quaternions don't have a rotation matrix. They are both ways of completely describing a rotation in 3D, so they are freely convertible. Each quaternion corresponds to exactly one rotation matrix, and each rotation matrix corresponds to one quaternion and its negative. Quaternions are just more compact and easier to interpolate.

To work out the rotation matrix for a quaternion, you need to take the effect of the quaternion, $q = (w, x, y, z) = (w, \textbf{v}) $ on some point $\textbf{p}$, that is, $(w, \textbf{v}) \* (0, \textbf{p}) \* (w, \textbf{-v}) $, and express this formula as a matrix operating on $\textbf{p}$.

Multiplying out using the rules of quaternions gives us $(w^2 - \textbf{v.v})\textbf{p} + 2( w\textbf{v}\times \textbf{p} + \textbf{(v.p)v}) $

This can be rearranged into 3 matrix terms - the first part is just a constant value down the diagonal, the second part with the cross product has values everywhere *except* the diagonal, and the third one is simply $\textbf{v}\_m \* \textbf{v}\_n $ for rows m and columns n.

Adding these 3 matrices together gives you

$\begin{bmatrix} 1-2(y^2+z^2) &2(xy-zw) & 2(xz+yw)\\2(xy + zw)&1-2(x^2+z^2) & 2(yz-xw)\\2(xz-yw) & 2(yz + xw) & 1 - 2(x^2+y^2)\end{bmatrix}$

which is the conversion you need.

In your particular use case, though, you are just doing a simple rotate-x through 90 degrees, which simplifies things a lot. Remember a quaternion is $ ( cos(\theta/ 2) , sin(\theta/ 2)\textbf{a})$ where $\textbf{a}$ is your normalized axis of rotation. So the quaternion representing ±90 degrees rotation around x will be $( \frac{1}{\sqrt{2}},±\frac{1}{\sqrt{2}},0,0)$

> **Comments:**
> **username_1**: "*Quaternions are just more compact and easier to interpolate.*" And easier to re-orthonormalize after applying successive rotations.  
> **username_4**: @username_1 or more accurately they are never not orthogonal. They only need renormalization which you can often delay for quite a bit. Or you can embrace the length as a uniform scaling factor, though you would need to adjust the matrix a bit replacing the 1 terms with the squared length of the quaternion.  

---

