<p>I want to start with misconceptions:</p>

<p>Modern GPUs (NVIDIA for quite a while, and AMD since Southern Islands) do not meaningfully support vector/matrix operations natively in hardware. They are vector architectures in a different direction: each component of a vector (x, y, z) are generally 32- or 64-valued, containing values for each element in a lane. So a 3D dot product is not usually an instruction, it is a multiply and two multiply-adds.</p>

<p>Additionally, counting primitive operations like multiply-add, transforming a vector by a quaternion is more expensive than transforming a vector by a matrix. Transforming a vector by a 3x3 matrix is 3 multiplies and 6 multiply-adds, and transforming a vector by a quaternion is two quaternion multiplies, each of which consist of 4 multiplies and 12 multiply-adds. (You can get less naïve than this—<a href="https://molecularmusings.wordpress.com/2013/05/24/a-faster-quaternion-vector-multiplication/" rel="noreferrer">here's a writeup on a faster way</a>—but it's still not as cheap as multiplying a vector by a matrix.)</p>

<p>However, performance is not always determined simply by counting the number of ALU operations it performs. Quaternions require less space than the equivalent matrix (assuming you are only doing pure rotation/scale), and that means less storage space and less memory traffic. This is often important in animation (which is conveniently also often where the nice interpolation properties of quaternions show up).</p>

<p>Other than that:</p>

<ul>
<li>Matrices use more space because they support more operations. A 3x3 matrix can contain nonuniform scale, skew, reflection, and orthogonal projection.</li>
<li>Matrices can be naturally thought of as basis vectors, and easily constructed from those vectors.</li>
<li>Multiplying one quaternion by another (composing two rotations) is less operations than multiplying one matrix by another.</li>
</ul>

CC BY-SA 3.0
2016-09-08T15:14:00.117Z
Funny, and on Intel Haswell GPU ARBfp's `DP3` instruction appears implemented as 3 multiplies and 2 additions, see `INTEL_DEBUG=fs` output from Intel Linux driver: http://paste.ubuntu.com/23150494/ . Not sure whether it's just poor driver or the HW really doesn't have special vector mul instructions.
Ruslan
CC BY-SA 3.0
2016-09-08T18:17:01.540Z
@Ruslan Very likely that hardware just doesn't have special vector mul instructions. More accurately, though, they _do_, but they are vectorized across the SIMD width of the architecture (the lanes), not vectorized across the vec3/vec4 dimension.
John Calsbeek
CC BY-SA 3.0
2015-08-09T17:16:24.560Z
2015-08-09T17:22:51.250Z
2015-08-09T17:22:51.250Z
John Calsbeek
<p>(A lot of information here I shamelessly borrowed from joojaa's and ratchet freak's answers, with some notes of my own.)</p>

<h2>Matrix Advantages</h2>

<ul>
<li>Non uniform scaling and rotation, skewing, projection</li>
<li>Translation (unless using dual quaternions)</li>
<li>Native hardware support</li>
<li>Quaternions often require transcendental functions to construct</li>
<li>Easier to understand</li>
</ul>

<h2>Quaternion Advantages</h2>

<ul>
<li>Transforming a vector requires fewer operations (Or not - See John's answer)</li>
<li>Transforming by another quat requires many fewer operations</li>
<li>Quaternions occupy 4 floats, (8 if it's a dual) but Matrices occupy 9-16 floats</li>
</ul>

<p>If you know you're only going to be doing uniform rigid body transforms, a vector/quat pair is usually a solid win on a 3x4 matrix in terms of storage space (vector/quat: 7 or 8 floats vs mat3x4: 12 floats) and processing speed. If Quaternions are still mystical voodoo to you, try <a href="https://www.youtube.com/playlist?list=PLW3Zl3wyJwWNWsJIPZrmY19urkYHXOH3N" rel="noreferrer">this web series on them</a>.</p>

CC BY-SA 3.0
2015-08-09T15:58:55.490Z
2015-08-09T17:20:16.970Z
2015-08-09T17:20:16.970Z
Jorge Rodriguez
<p>A quaternion can only represent uniform scaling and rotation so if you need anything else you would need to add something to represent that. </p>

<p>Translation can be done with a single additional vec3 (or using <a href="https://en.wikipedia.org/wiki/Dual_quaternion" rel="nofollow">dual quaternions</a>). However non-uniform scaling and sheering is represented better by a mat4. Projection transforms (essentially non-uniform scaling and swapping z and w) cannot be represented by a quaternion.</p>

<p>Quaternions have a major advantage when interpolating. The slerp is most easily calculated using quaternions. </p>

<p>Applying a quaternion (or dual quaternion) is not built into the GPU so you would need to implement that using the vector operations. Most quaternion libraries assume that you won't be using the quaternion to represent scale so that's something to look out for.</p>

CC BY-SA 3.0
2015-08-09T13:27:07.007Z
2015-08-09T16:44:50.557Z
2015-08-09T16:44:50.557Z
ratchet freak
<p>Matrices offer more possible transforms than quaternions, it is possible to skew, mirror and non uniformly scale the matrix. There is nothing that states you can not make your engine do just quaternion based transforms, if you have no need for the additional transform features.</p>

<p>Matrices are just very convenient when you need to build spaces where you know the basis vectors. Such as when doing projections into orthographic. Also doing perspective transform in a matrix space is easy. Matrices are superior when it comes to projecting stuff.</p>

<p>In a way matrices are usually used because they represent the most common denomination and aren't too complicated to master and understand. The benefits of standardization far outweighs the benefit you get form a custom workflow. Its well known how to do the matrix operations. Whereas quats are not something most get immediate introduction to in uni. Just ask around how many know how to invert a quaternion, whereas you dont find many students in higher education who dont know how to invert a matrix. </p>

<p>Note that graphics cards also have dedicated pipes for matrix operations.</p>

CC BY-SA 3.0
2015-08-09T13:17:36.497Z
I've actually been thinking about this. Ive also toyed on asking what other approaches modeling pipes than matrix and quat hierarchies one could use.
joojaa
CC BY-SA 3.0
2015-08-09T13:16:41.053Z
2015-08-09T13:30:27.103Z
2015-08-09T13:30:27.103Z
joojaa
<p>Quaternions (a four-dimensional extension of complex numbers) can used to represent rotation and scaling of a 3D vector, and the application of a quaternion onto a 3D vector involves two quaternion multiplications, thus requiring fewer operations than multiplication by the corresponding transformation matrix. However, linear and affine transformation matrixes are often used instead, especially in shader code.</p>

<p>When is it appropriate and preferable (due to speed, stability, etc.) to use a quaternion to represent scaling and rotation in three dimensions, instead of the corresponding transformation matrix?</p>

CC BY-SA 3.0
2015-11-10T09:05:28.537Z
[Also see this related question on GameDev SE.](http://gamedev.stackexchange.com/q/111051/19876)
Martin Ender
<transformations>
When should quaternions be used to represent rotation and scaling in 3D?
es1024
# When should quaternions be used to represent rotation and scaling in 3D?

(Asked by: username_0 on 2015-08-09)

Quaternions (a four-dimensional extension of complex numbers) can used to represent rotation and scaling of a 3D vector, and the application of a quaternion onto a 3D vector involves two quaternion multiplications, thus requiring fewer operations than multiplication by the corresponding transformation matrix. However, linear and affine transformation matrixes are often used instead, especially in shader code.

When is it appropriate and preferable (due to speed, stability, etc.) to use a quaternion to represent scaling and rotation in three dimensions, instead of the corresponding transformation matrix?

**Tags:** transformations

> **Comments:**
> **username_1**: [Also see this related question on GameDev SE.](http://gamedev.stackexchange.com/q/111051/19876)  

---

## 4 answers

### Answer by username_2 on 2015-08-09. Score: 9

I want to start with misconceptions:

Modern GPUs (NVIDIA for quite a while, and AMD since Southern Islands) do not meaningfully support vector/matrix operations natively in hardware. They are vector architectures in a different direction: each component of a vector (x, y, z) are generally 32- or 64-valued, containing values for each element in a lane. So a 3D dot product is not usually an instruction, it is a multiply and two multiply-adds.

Additionally, counting primitive operations like multiply-add, transforming a vector by a quaternion is more expensive than transforming a vector by a matrix. Transforming a vector by a 3x3 matrix is 3 multiplies and 6 multiply-adds, and transforming a vector by a quaternion is two quaternion multiplies, each of which consist of 4 multiplies and 12 multiply-adds. (You can get less naïve than this—[here's a writeup on a faster way](https://molecularmusings.wordpress.com/2013/05/24/a-faster-quaternion-vector-multiplication/)—but it's still not as cheap as multiplying a vector by a matrix.)

However, performance is not always determined simply by counting the number of ALU operations it performs. Quaternions require less space than the equivalent matrix (assuming you are only doing pure rotation/scale), and that means less storage space and less memory traffic. This is often important in animation (which is conveniently also often where the nice interpolation properties of quaternions show up).

Other than that:

* Matrices use more space because they support more operations. A 3x3 matrix can contain nonuniform scale, skew, reflection, and orthogonal projection.
* Matrices can be naturally thought of as basis vectors, and easily constructed from those vectors.
* Multiplying one quaternion by another (composing two rotations) is less operations than multiplying one matrix by another.

> **Comments:**
> **username_3**: Funny, and on Intel Haswell GPU ARBfp's `DP3` instruction appears implemented as 3 multiplies and 2 additions, see `INTEL_DEBUG=fs` output from Intel Linux driver: http://paste.ubuntu.com/23150494/ . Not sure whether it's just poor driver or the HW really doesn't have special vector mul instructions.  
> **username_2**: @username_3 Very likely that hardware just doesn't have special vector mul instructions. More accurately, though, they _do_, but they are vectorized across the SIMD width of the architecture (the lanes), not vectorized across the vec3/vec4 dimension.  

---

### Answer by username_4 on 2015-08-09. Score: 6

(A lot of information here I shamelessly borrowed from username_6's and username_5's answers, with some notes of my own.)

## Matrix Advantages

* Non uniform scaling and rotation, skewing, projection
* Translation (unless using dual quaternions)
* Native hardware support
* Quaternions often require transcendental functions to construct
* Easier to understand

## Quaternion Advantages

* Transforming a vector requires fewer operations (Or not - See username_2's answer)
* Transforming by another quat requires many fewer operations
* Quaternions occupy 4 floats, (8 if it's a dual) but Matrices occupy 9-16 floats

If you know you're only going to be doing uniform rigid body transforms, a vector/quat pair is usually a solid win on a 3x4 matrix in terms of storage space (vector/quat: 7 or 8 floats vs mat3x4: 12 floats) and processing speed. If Quaternions are still mystical voodoo to you, try [this web series on them](https://www.youtube.com/playlist?list=PLW3Zl3wyJwWNWsJIPZrmY19urkYHXOH3N).


---

### Answer by username_5 on 2015-08-09. Score: 3

A quaternion can only represent uniform scaling and rotation so if you need anything else you would need to add something to represent that.

Translation can be done with a single additional vec3 (or using [dual quaternions](https://en.wikipedia.org/wiki/Dual_quaternion)). However non-uniform scaling and sheering is represented better by a mat4. Projection transforms (essentially non-uniform scaling and swapping z and w) cannot be represented by a quaternion.

Quaternions have a major advantage when interpolating. The slerp is most easily calculated using quaternions.

Applying a quaternion (or dual quaternion) is not built into the GPU so you would need to implement that using the vector operations. Most quaternion libraries assume that you won't be using the quaternion to represent scale so that's something to look out for.


---

### Answer by username_6 on 2015-08-09. Score: 3

Matrices offer more possible transforms than quaternions, it is possible to skew, mirror and non uniformly scale the matrix. There is nothing that states you can not make your engine do just quaternion based transforms, if you have no need for the additional transform features.

Matrices are just very convenient when you need to build spaces where you know the basis vectors. Such as when doing projections into orthographic. Also doing perspective transform in a matrix space is easy. Matrices are superior when it comes to projecting stuff.

In a way matrices are usually used because they represent the most common denomination and aren't too complicated to master and understand. The benefits of standardization far outweighs the benefit you get form a custom workflow. Its well known how to do the matrix operations. Whereas quats are not something most get immediate introduction to in uni. Just ask around how many know how to invert a quaternion, whereas you dont find many students in higher education who dont know how to invert a matrix.

Note that graphics cards also have dedicated pipes for matrix operations.

> **Comments:**
> **username_6**: I've actually been thinking about this. Ive also toyed on asking what other approaches modeling pipes than matrix and quat hierarchies one could use.  

---

