logo back up home forward   further reading more topics »

Maths - Derivation of Expressions

Rotation

So why do we use an equation like: Pout = q * Pin * conj(q) to rotate a point?

We can demonstrate it works by expanding out the parts of the complex number using:

So using the above equation and expanding out the terms gives:

Pout.x = x*(qx*qx+qw*qw-qy*qy- qz*qz) + y*(2*qx*qy- 2*qw*qz) + z*(2*qx*qz+ 2*qw*qy)
Pout.y = x*(2*qw*qz + 2*qx*qy) + y*(qw*qw - qx*qx+ qy*qy - qz*qz)+ z*(-2*qw*qx+ 2*qy*qz)
Pout.z = x*(-2*qw*qy+ 2*qx*qz) + y*(2*qw*qx+ 2*qy*qz)+ z*(qw*qw - qx*qx- qy*qy+ qz*qz)

The full working is shown on this page, its hard to see whats happening here so it may help to show the same equations in the form of a matrix:

Pout.x
Pout.y
Pout.z
=
qx*qx+qw*qw-qy*qy- qz*qz 2*qx*qy- 2*qw*qz 2*qx*qz+ 2*qw*qy
2*qw*qz + 2*qx*qy qw*qw - qx*qx+ qy*qy - qz*qz -2*qw*qx+ 2*qy*qz
-2*qw*qy+ 2*qx*qz 2*qw*qx+ 2*qy*qz qw*qw - qx*qx- qy*qy+ qz*qz
Pin.x
Pin.y
Pin.z

We can compare this with other matrix forms for rotation and therefore convince ourselves that this represents a rotation.

However, although this shows that the equation gives the result we want, it does not really explain why the equation is in this form.

We can try doing the same expansion but using the scalar and vector notation as shown on this page.

Reflection and Projections

We can use the Geometric Algebra inner and outer product to represent the perpendicular and parrallel components to a plane as follows:

Parallel Component of a Point

parallel component

The parallel component is denoted as follows:

A || B = (A•B) B-1

Where:

But we know from Geometric algebra that,

A•B = ½ (AB + BA)

So substituting in the above equation gives:

A || B = ½ (AB + BA) B-1

A || B = ½ (A + BAB-1)

Converting this to quaternion terminology gives:

Pout = ½ Pin + q * Pin * conj(q)

but in this case the real part of q is zero (unlike quaternions representing rotations) therefore: conj(q) = -q

So we have:

Pout = ½ Pin - q * Pin * q

Perpendicular Component of a Point

perpendicular component

The perpendicular component is denoted as follows:

A project B = (A ^ B) B-1

But we know from Geometric algebra that,

A^B = ½ (AB - BA)

So substituting in the above equation gives:

A project B = ½ (AB - BA) B-1

A project B = ½ (A - BAB-1)

Converting this to quaternion terminology gives:

Pout = ½ Pin - q * Pin * conj(q)

but in this case the real part of q is zero (unlike quaternions representing rotations) therefore: conj(q) = -q

So we have:

Pout = ½ Pin + q * Pin * q

Reflection in a Plane

From the above diagrams we can see that:

P1 = (P1 || B) + (P1 project B)

In other words the parallel component plus the perpendicular component is the point itself.

However to get the point reflected in the plane (P2) we keep the parallel component the same but invert the perendicular component:

P2 = (P1 || B) - (P1 project B)

P2 = (P1•B) B-1 - (P1 ^ B) B-1

P2 = ((P1•B) - (P1 ^ B)) B-1

Since the inner product commutes in 3D and the outer product anticommutes we get:

P2 = ((B•P1) + (B^P1)) B-1

We know from Geometric Algebra that the geometric product is the sum of the inner and outer products:

B A = B•A + B^A

so we get:

P2 = B P1 B-1

Converting this to quaternion terminology gives:

Pout = q * Pin * conj(q)

since conj(q) = -q we get:

Pout = - q * Pin * q


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.