Drag your mouse over the globe to rotate it. You can choose "correct" rotation or "naive" rotation below.
Hitting the "information" button gives a bit of the background of what is going on.
Correct Quaternion Rotation P' = QPQ*
Naive Quaternion Rotation P' = (V2)(-V1)P
What not to expect from Quaternions.
You will enjoy the story of William Rowan Hamilton and his search for finding a
3D algebra that would rotate a 3D vector similar to the way the 2D algebra
(complex numbers) can rotate 2D vectors.
16 October 1843: (http://mathshistory.st-andrews.ac.uk/Biographies/Hamilton.html)
But be warned by Lord Kelvin:
Quaternions came from Hamilton after his really good work had been done,
and though beautifully ingenious, have been an unmixed evil to those who
have touched them in any way.
A 3D algebra was not to be found. The answer was a 4D algebra, the quaternions.
The bottom line is that a point P can be rotated around a unit axis (xu, yu, zu)
for an angle θ using quaternions:
Point P is the vector quaternion (0, xp, yp, zp).
Quaternion Q is the rotation quaternion
(cos(θ/2), xu*sin(θ/2), yu*sin(θ/2), zu*sin(θ/2)).
P' is the rotated point.
Q* is the conjugate of Q.
The formula is
P' = QPQ* which is the conjugation of P by Q.
Quaternion multiplication and conjugation links:
https://en.wikipedia.org/wiki/Quaternion#Hamilton_producthttps://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation#The_conjugation_operation
A common desire is to find a rotation that rotates a vector V1 into V2.
The "correct" solution(s) for quaternion Q is not obvious but can be found.
http://lolengine.net/blog/2013/09/18/beautiful-maths-quaternion-from-vectors
A naive approach is to look to find Q from the equation
V2 = QV1
This is easy. Multiply on the right by (-V1), the conjugate of V1.
V2(-V1) = QV1(-V1) = Q (because V1(-V1) gives the unit quaternion)
and we have Q. And the "rotation" for points P should be
P' = QP = V2(-V1)P
Unfortunately, it's not a true rotation. It does transform V1 into V2, but it does
horrible things to other points in the world. (Qcorrect and Qnaive are closely
related: Qcorrect*Qcorrect = Qnaive.)
Rotating the globe with the "correct" option gives correct results. Rotating the
globe with the "naive" option shows the distorted results. In both cases V1
(the starting point) does transform into V2 (the ending point) -- the yellow line.
Drag from +45 to -45, re-select the "correct" option, and see what you have done.