Maths - Vector Expansion

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:

(sq,vq)(0,vp)(sq,-vq)

As explained on this page quaternion multipication can be defined using scalar and vector as: (sa,va) * (sb,vb) = (sa*sb-va•vb,va x vb + sa*vb + sb*va) so multiplying the first two gives:

(sq,vq)(-vp•vq,-vp x vq + sq*vp)

now expand out the second operand:

(-sq*(vp•vq) + vq•(-vp x vq + sq*vp) , - vq x (-vp x vq + sq*vp) + sq*(-vp x vq + sq*vp) - vq*(vp•vq))

which simplifies to (see forum discussion):

(- vq•(vp x vq) , vq x (vp x vq) - sq*2*(vp x vq) + sq*sq*vp - vq*(vp•vq))

Since (vq x vp) gives a vector which is mutually perpendicular to vq and vp then (vq x vp)•vp=0, therefore the scalar part is zero which is what we want:

(0 , - vq x (vp x vq) + sq*2*(vp x vq) + sq*sq*vp - vq*(vp•vq))

using the triple product for cross product: A x (B x C) = B (A•C) - C (A•B) we get:

(0 , -vp (vq•vq) + 2*vq (vq•vp) - sq*2*(vp x vq) + sq*sq*vp)

So the result of the rotation is a vector:

-vp (vq•vq) + 2*vq (vq•vp) - sq*2*(vp x vq) + sq*sq*vp

where:

To try to understand this we can express it in matrix form, first lets calculate the matrix equivalent of each part:

-vp (vq•vq)
= vp*(vqx*vqx+vqy*vqy+vqz*vqz)
-vqx2-vqy2-vqz2 0 0
0 -vqx2-vqy2- vqz2 0
0 0 -vqx2- vqy2- vqz2
vpx
vpy
vpz

2*vq (vq•vp)
= 2*(vqx+vqy+vqz)(vqx*vpx + vqy*vpy + vqz*vpz)
= 2*vpx*vqx*(vqx+vqy+vqz)+
2*vpy*vqy*(vqx+vqy+vqz)+
2*vpz*vqz*(vqx+vqy+vqz)

2*vqx*vqx 2*vqx*vqy 2*vqx*vqz
2*vqy*vqx 2*vqy*vqy 2*vqy*vqz
2*vqz*vqx 2*vqz*vqy 2*vqz*vqz
vpx
vpy
vpz
- sq*2*(vp x vq)
0 -2*sq*vqz 2*sq*vqy
2*sq*vqz 0 -2*sq*vqx
-2*sq*vqy 2*sq*vqx 0
vpx
vpy
vpz
+sq*sq*vp
sq2 0 0
0 sq2 0
0 0 sq2
vpx
vpy
vpz
adding these —————————————————————
total:
-vqx2+vqy2+vqz2 + sq2 2*vqx*vqy-2*sq*vqz 2*vqx*vqz+2*sq*vqy
2*vqy*vqx + 2*sq*vqz vqx2- vqy2+vqz2+ sq2 2*vqy*vqz-2*sq*vqx
2*vqz*vqx - 2*sq*vqy 2*vqz*vqy + 2*sq*vqx vqx2+vqy2- vqz2+ sq2

This is the expected result (derived here):

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

where

Reflection - expansion of result using scalar and vector format

We can expand out all the terms of the rotation as follows:

P2=q * P1 * q

(0,vq)(0,vp)(0,vq)

As explained on this page quaternion multipication can be defined using scalar and vector as: (sa,va) * (sb,vb) = (sa*sb-va•vb,va x vb + sa*vb + sb*va) so multiplying the first two gives:

(0,vq)(-vp•vq,vp x vq)

(-vq•(vp x vq),vq x (vp x vq) + (-vp•vq)*vq)

(0,vq x (vp x vq) + (-vp•vq)*vq)

using the triple product for cross product: A x (B x C) = B (A•C) - C (A•B) we get:

(0,vp (vq•vq) - vq (vq•vp) - (vp•vq)*vq)

(0,vp (vq•vq) - 2*vq (vq•vp))

To try to understand this we can express it in matrix form, first lets calculate the matrix equivalent of each part:

vp (vq•vq)
= vp*(vqx*vqx + vqy*vqy + vqz*vqz)
vqx*vqx + vqy*vqy + vqz*vqz 0 0
0 vqx*vqx + vqy*vqy + vqz*vqz 0
0 0 vqx*vqx + vqy*vqy + vqz*vqz
vpx
vpy
vpz

- 2*vq (vq•vp)
= -2*(vqx+vqy+vqz)(vqx*vpx + vqy*vpy + vqz*vpz)
= -2*vpx*vqx*(vqx+vqy+vqz)-
2*vpy*vqy*(vqx+vqy+vqz)-
2*vpz*vqz*(vqx+vqy+vqz)

-2*vqx*vqx -2*vqx*vqy -2*vqx*vqz
-2*vqy*vqx -2*vqy*vqy -2*vqy*vqz
-2*vqz*vqx -2*vqz*vqy -2*vqz*vqz
vpx
vpy
vpz
adding these —————————————————————
total:
vqy*vqy + vqz*vqz-vqx*vqx -2*vqx*vqy -2*vqx*vqz
-2*vqy*vqx vqx*vqx + vqz*vqz-vqy*vqy -2*vqy*vqz
-2*vqz*vqx -2*vqz*vqy vqx*vqx + vqy*vqy -vqz*vqz

Which agrees with the result on this page:

Refl = 1 / (Px2 + Py2 + Pz2)*
-Px2 + Pz* Pz + Py* Py - 2 * Px * Py - 2 * Px * Pz
- 2 * Py * Px -Py2 + Px*Px + Pz*Pz - 2 * Py * Pz
- 2 * Pz * Px -2 * Pz * Py -Pz2 + Py*Py + Px*Px
[Va]

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.

Terminology and Notation

Specific to this page here:

 

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

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