logo back up home forward   further reading more topics »

Maths - Quaternion Notations - As a Scalar and Vector

We can think of quaternions as an element consisting of a scalar number together with a 3 dimensional vector. In other words we have combined the 3 imaginary values into a vector.

We could denote it like this: (s,v)

where:

So the quaternion still has 4 degrees of freedom, its just that we group the 4 scalars as 1+3 scalars, the quaternion is still an element but the vector is a sub-element within it (if that's not a contradiction in terms).

One advantage of sub-grouping the quaternion in this way is that it simplifies the relationship between quaternions and axis-angle representation of 3D rotations.

As discussed here, a quaternion can be represented in terms of axis-angle, in the usual notation this is:

q = cos(a/2) + i ( x * sin(a/2)) + j (y * sin(a/2)) + k ( z * sin(a/2))

where:

Converting this to scalar & vector form simplifies this as follows,

q = (s*cos(a/2), v *sin(a/2))

If this represents a pure rotation

q = (cos(a/2), axis*sin(a/2))

where:

An advantage in using a vector to build a quaternion is that we can use vector algebra on it. Imagine a point P1 which is a unit distance from the origin, we will be rotating it through an angle (a) to P3 through midpoint P2.

axis angle

This diagram is explained here.

If we take the cross product of P1 and P2 we get a vector along the rotation axis, because it is mutually perpendicular to both, and since P1 and P2 are on the unit length circle the cross product will be unit length so:

P1 × P2 = axis

where:

Similarly cross multiplying P2 and P3 will give exactly the same vector:

P1 × P2 = P2 × P3 = axis

We can now try the dot product, as explained here, if A and B make angle theta :

A•B = |A| |B| cos(theta)

Since P1 and P2 are unit length:

P1•P2 = cos(a/2)

Similarly with P2 and P3:

P1•P2 = P2•P3 = cos(a/2)

Therefore:

q = (P1•P2, P1 x P2)

Note: P2 is the mid point of the rotation, if we want this in terms of the endpoint vectors we could substitute:

P2 = (P1+P3)/ |P1+P3|

So this gives the quaternion representing the rotation in terms vectors representing a point being rotated. However, we frequently want to do the reverse of this, often we already know the quaternion representing the rotation and we want to know how this will transform a given point.

To do this we will create quaternions representing the the vectors by setting the scalar part to zero, so we let,

From this page we know:

q*q1 = q2

and

q' = q2*q3'

multiplying these together gives:

q*q1*q' = q2*q2*q3'

q*q1*q' = -q3'

q*q1*q' = q3

Arithmatic Using Scalar and Vector Notation

On this page we defined quaternion arithmetic in terms of qw, qx, qy and qz but we can also define the arithetic operations in terms of scalar and vector notation:

(sa,va) + (sb,vb) = (sa+sb,va+vb)
(sa,va) - (sb,vb) = (sa-sb,va-vb)
(sa,va) * (sb,vb) = (sa*sb-va•vb,va × vb + sa*vb + sb*va)
(sa,va) / (sb,vb) = (sa*sb+va•vb,-va × vb - sa*vb + sb*va)

where:


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.

 

cover us uk de jp fr ca Quaternions and Rotation Sequences.

Commercial Software Shop

Where I can, I have put links to Amazon for commercial software, not directly related to the software project, 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.

 

cover Dark Basic Professional Edition - It is better to get this professional edition

cover 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

cover Game Programming with Darkbasic - book for above software

Can you help?

Please send me any improvements to here. I would appreciate ideas to make the pages more useful including error correction, ideas for new pages, improvements to wording. It helps if you quote the full URL of the page.

 

Terminology and Notation

Specific to this page here:

 

program

I am working on a project which uses these principles, if you would like to help me with this you are welcome to join in, here:

http://sourceforge.net/projects/mjbworld/

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

Copyright (c) 1998-2008 Martin John Baker - All rights reserved.