# 3D Theory - Matrix vs. Quaternion

If we want to model 3 dimensional rotations, is it best to use matrices or quaternions?

## Pure Rotations

If we want our program to combine 3 dimensional rotations then we have a choice of using 3x3 matrices or quaternions. So which should we use? Provided that we constrain the values in the matrix to be an orthogonal matrix then both algebras are mathematically equivalent so our choice can be made on practical issues.

### The advantages of quaternions are:

• Each quaternion only requires 4 scalars whereas a matrix requires 9 scalars.
• It is easier to interpolate between quaternions using SLERP as explained on this page.
• Quaternions are easier to normalise than matrices (to cancel out a build up of small rounding errors).

### The advantages of matrices are:

• Transforming a point seems simpler by multiplying a vector by a matrix rather than the sandwich form required for quaternions.
• People often find matrices easier to understand than quaternions.
• There are more ready built matrix libraries than quaternion libraries.

### Conclusions

I don't think there is a clear winner, it depends on what you are most comfortable with and what tools are available for your program. I have not done any tests of relative speed but I don't think there is much to choose between them, the matrix has more scalars but this is cancelled out by the more complicated equations for transforming a point.

## Isometries and Physics

If we want to model isometries, such as the movement of solid bodies, combining rotation and translation, in one single operation, we need to expand the above algebras to model translations as well as rotations.

To model isometries we could either:

• Expand matrices to 4x4 as described on this page.
• Expand quaternions to dual quaternions as described on this page.

Again matrices tend to be easier to understand for most programmers, dual quaternions have a lop sided multiplication table in which some dimensions have non-zero values which square to zero.

So can we extend these algebras to model physics? For example, modeling forces/torques and their effect on linear/angular acceleration. To do this we need to:

• Extend the inertia tensor to a 6x6 matrix which includes mass as described on this page.
• In his books, Hestenes explains how Geometric Algebra can model tensors and how it is less dependant on the choice of coordinates, but I don't understand this yet but I'm still working on it.

## Conclusions

So far, matrices seem to be able to model of these things than quaternion-like algebras, but I'm still working on this and I think that Geometric algebra may have a lot of advantages.

metadata block
see also:
Correspondence about this page

Book Shop - Further reading.

Where I can, I have put links to Amazon for books that are relevant to the subject, click on the appropriate country flag to get more details of the book or to buy it from them.      New Foundations for Classical Mechanics (Fundamental Theories of Physics). This is very good on the geometric interpretation of this algebra. It has lots of insights into the mechanics of solid bodies. I still cant work out if the position, velocity, etc. of solid bodies can be represented by a 3D multivector or if 4 or 5D multivectors are required to represent translation and rotation.

Commercial Software Shop

Where I can, I have put links to Amazon for commercial software, not directly related to this site, but related to the subject being discussed, click on the appropriate country flag to get more details of the software or to buy it from them.   Dark Basic Professional Edition - It is better to get this professional edition    This is a version of basic designed for building games, for example to rotate a cube you might do the following: make object cube 1,100 for x=1 to 360 rotate object 1,x,x,0 next x

This site may have errors. Don't use for critical systems.

Copyright (c) 1998-2020 Martin John Baker - All rights reserved - privacy policy.