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))
(- 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 |
|
|
|
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 |
|
|
|
| - 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 |
|
|
|
| +sq*sq*vp |
|
| 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
- 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 |
|
|
|
- 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 |
|
|
|
| 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. |
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. |
|
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.