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:

• q = (sq,vq)
• q' = (sq,-vq)
• Pin = (0,vp)

(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:

• vp = input vector
• sq = cos(rotation angle/2)
• vq = rotation axis * sin(rotation angle/2)

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
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

• sq = qw = cos(angle/2)
• (qx,qy,qz) = axis*sin(angle/2)

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
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