MATEC Web of Conferences 292, 0 10 60 (2019) https://doi.org/10.
1051/matecconf/2019292010 60
CSCC 2019
Universal approach to derivation of quaternion rotation formulas
Hana Chudá1,∗
1
Tomas Bata University in Zlín, Faculty of Applied Informatics, Nad Stráněmi 4511, 760 05, Zlín, Czech Republic
Abstract. This paper introduces and defines the quaternion with a brief insight into its properties and algebra.
The main part of this paper is devoted to the derivation of basic equations of the vector rotation around each
rotational x, y, z axis. Then, the equations of generalized quaternion rotation and express the general rotation
operator is derived. Finally the utilization of equations is demonstrated on a simple example. For purposes of
simplicity the quaternions theory is demonstrated around the z-axis by γ angle. For the purpose of this paper,
the fact that the subspace of vector quaternions may be regarded as being equivalent to the ordinary is used.
1 Introduction 2.2 Addition of quaternions
The development of quaternions is attributed to The addition rule for two quaternions is component-wise
W. R. Hamilton in 1843. The great mathematician addition. This rule preserves the associativity and the com-
Sir W. R. Hamilton had been interested in complex mutativity properties of addition:
numbers in the form a + b i, where numbers a, b are real p+q = (p1 + p2 i + p3 j + p4 k) +
and the unit i is imaginary. The rank of complex numbers + (q1 + q2 i + q3 j + q4 k) = (p1 + q1 ) + (3)
in the plane is 2. Some mathematicians sought other + i (p2 + q2 ) + j (p3 + q3 ) + k (p4 + q4 ).
mathematical systems over the complex numbers the rank
more than 2. Sir Hamilton for over 10 years tried to
extend concepts of complex numbers in the plane in order
to define a complex volume by searching for the second 2.3 Multiplication of quaternions
imaginary axis. And on 16th October 1843 he invented The multiplication rule for the quaternions is the same as
the so-called hyper-complex numbers of the rank 4 with 3 for the polynomials, extended by the multiplicative prop-
imaginary units needed. erties of the elements i, j, k given above. We have:
p·q = (p1 + p2 i + p3 j + p4 k) ⊗
2 The algebra of quaternions ⊗ (q1 + q2 i + q3 j + q4 k) =
2.1 Definition of quaternions = (p1 q1 − p2 q2 − p3 q3 − p4 q4 ) +
+ i (p1 q2 + p2 q1 + p3 q4 − p4 q3 ) + (4)
The definition of the real quaternion is expressed in the + j (p1 q3 + p3 q1 + p4 q2 − p2 q4 ) +
form
+ k (p1 q4 + p4 q1 + p2 q3 − p3 q2 ).
q = q1 + q2 i + q3 j + q4 k (1)
where q1 , q2 , q3 , q4 are real numbers and i, j, k of q
The foregoing term reveals that the commutativity cannot
are the imaginary units of quaternions, which satisfy the
be preserved. The associativity and the distributive prop-
equalities
erty over addition are preserved.
i2 =j2 = k 2 = ijk = −1;
ij = −ji = k; (2) 2.4 Conjugates of quaternions
ki = −ik = j; Consistent with the complex numbers, the definition of the
jk = −kj = i. conjugate operation on a given quaternion q is
Set of all quaternions are denoted H. The quater- q = (q1 + q2 i + q3 j + q4 k) = (5)
nion, q ∈ H is defined as a pair (S (q), V(q)), where = q1 − q2 i − q3 j − q4 k.
S (q) = q1 ∈ R is the scalar part of quaternion q and
As with the complex numbers, note that both (q + q) and
V(q) = q2 i + q3 j + q4 k, is the vector part of the quater-
(q·q) are the real numbers. Moreover, defining the absolute
nion.
value or the norm the equation is to be
q = S (q) + V(q). q
∗ e-mail: chuda@utb.cz |q| = q1 2 + q2 2 + q3 2 + q4 2 . (6)
© The Authors, published by EDP Sciences. This is an open access article distributed under the terms of the Creative Commons Attribution License 4.0
(http://creativecommons.org/licenses/by/4.0/).
MATEC Web of Conferences 292, 0 10 60 (2019) https://doi.org/10.1051/matecconf/2019292010 60
CSCC 2019
2.9 Product of vector quaternions
Then evidently (q · q) = (q · q) = |q2 |. The conjugate oper-
ation is distributive over addition. The product of two vector quaternions has an interesting
property
2.5 Unit quaternion
p·q = (p2 i + p3 j + p4 k) · (q2 i + q3 j + q4 k) =
The subspace of the unit quaternions, satisfying the con- = −(p2 q2 + p3 q3 + p4 q4 ) +
dition |q| = 1, have some important properties. A trivially + i (p3 q4 − p4 q3 ) + (11)
hold + j (p4 q2 − p2 q4 ) +
+ k (p2 q3 − p3 q2 ) =
|q| = |q| = 1 and q·q=q·q=1
= −p · q + p × q,
And a very useful form is
q = S (q) · cos θ + V(q) · sin θ = cos θ + V(q) · sin θ, (7) where ”.” is an operator of the real part of the quaternion
and ” × ” is an operator of the vector parts of the quater-
where S(q)=(1, 0, 0, 0) is the scalar part of the unit quater- nions.
nion, V(q)=(0, q2 i, q3 j, q4 k) is the vector part of the unit
quaternion and θ is the real number.
3 Rotation quaternion
2.6 Inverse quaternions
The quaternion, which represents the rotation of the θ
We define the inverse quaternion in the following form: around the axis n = (n1 , n2 , n3 ) is given by
q = cos θ + n · sin θ = cos θ + (n1 i + n2 j + n3 k) · sin θ, (12)
q1 − q2 i − q3 j − q4 k q where q is the unit quaternion, also n is the unit vector of
q−1 = = 2, (8)
|q| 2 |q| the unit quaternion q. For any unit quaternion q = cos θ +
n·sin θ and for any vector p ∈ R3 he action of the operator
where |q| = q1 2 + q2 2 + q3 2 + q4 2 is absolute value of
p
Rq (p) = q · p · q (13)
the quaternion and q = q1 − q2 i − q3 j − q4 k is the con-
jugate quaternion. This expression was introduced by the may be interpreted geometrically as the rotation of the
equation q · q−1 = q−1 · q = 1. vector p through the angle 2θ around the q as the axis of
the rotation.
2.7 Vector properties of quaternions
The quaternion q = q1 + q2 i + q3 j + q4 k can be in-
terpreted as the scalar part q1 ∈ R and the vector part
q2 i + q3 j + q4 k, where the elements i, j and k are given the
added geometric interpretation as the unit vectors along
the x, y, z axes. Therefore, the subspace of the real quater-
nions may be regarded as being equivalent to the real num-
bers and subspace of the vector quaternions may be re-
garded as being equivalent to the ordinary vectors
q ≡ q x i + qy j + qz k. (9)
Figure 1. Rotation operator geometry.
This attribute is further used in our calculations.
2.8 Point as quaternion
3.1 Quaternion rotation around the z-axis by γ
If the point P = (x, y, z) is represented as the position vec-
tor, it can be represented as the quaternion
The rotation axis represents the unit quaternion
n = 0 i + 0 j + 1 k while the rotation operator is given by
q ≡ 0 + x i + y j + z k. (10)
γ γ γ γ
q = cos + n · sin = cos + k · sin .
2 2 2 2
2
MATEC Web of Conferences 292, 0 10 60 (2019) https://doi.org/10.1051/matecconf/2019292010 60
CSCC 2019
Using the rotation operator onto any vector Equation of the rotation operator Rq (p)y :
p = x i + y j + z k, p ∈ R3 : β β β β
Rq (p)y = i x cos2 − sin2 + 2z sin cos +
2 2 2 2
Rq (p)z = q·p·q= β β
γ γ + j y cos2 + sin2 + (15)
= (cos + k · sin ) · (xi + yj + zk) ⊗ 2 2
2 2 β β β β
γ γ + k z cos2 − sin2 − 2x sin cos .
⊗ (cos − k · sin ) = 2 2 2 2
2 2
γ γ γ
= x i cos2 + y j cos2 + z k cos2 +
2 2 2
γ γ γ γ 3.3 Quaternion rotation around the x-axis by α
+ x k i sin cos + y k j sin cos +
2 2 2 2
γ γ γ γ The rotation axis represents the unit quaternion
+ z k k sin cos − x i k sin cos −
2 2 2 2 n = 1 i + 0 j + 0 k while the rotation operator is given
γ γ γ γ
− y j k sin cos − z k k sin cos − by
2 2 2 2 α α α α
γ γ q = cos + n · sin = cos + i · sin .
− x k i k sin2 − y k j k sin2 − 2 2 2 2
2 2 Using the rotation operator onto any vector
2 γ
− z k k k sin . p = x i + y j + z k, p ∈ R3 :
2
Rq (p) x = q·p·q=
α α
Equation of the rotation operator Rq (p)z : = (cos + i · sin ) · (xi + yj + zk) ⊗
2 2
α α
γ γ γ γ ⊗ (cos − i · sin ) =
Rq (p)z = i x cos2 − sin2 − 2y sin cos + 2 2
2 2 2 2
γ γ γ γ 2 α α α
= x i cos + y j cos2 + z k cos2 +
+ j y cos2 − sin2 + 2x sin cos + 2 2 2
2 2 2 2 α α α α
γ γ
+ x i i sin cos + y i j sin cos −
+ k z cos2 + sin2 . (14) 2 2 2 2
2 2
α α α α
− z i k sin cos − x i i sin cos −
2 2 2 2
α α α α
− y j i sin cos − z k i sin cos −
2 2 2 2
2 α 2 α
3.2 Quaternion rotation around the y-axis by β − x i i i sin − y i j i sin
2 2
α
− z i k i sin2 .
The rotation axis represents the unit quaternion 2
n = 0 i + 1 j + 0 k while the rotation operator is given Equation of the rotation operator Rq (p) x :
by
α α
β β β β Rq (p) x = i x cos2 + sin2 + (16)
q = cos + n · sin = cos + j · sin . 2 2
2 2 2 2 α α α α
+ j y cos2 − sin2 − 2z sin cos +
Using the rotation operator onto any vector 2 2 2 2
α α α α
p = x i + y j + z k, p ∈ R3 : + k z cos2 − sin2 + 2y sin cos .
2 2 2 2
Rq (p)y = q·p·q=
β β
= (cos + j · sin ) · (xi + yj + zk) ⊗ 3.4 Operator of composition
2 2
β β
⊗ (cos − j · sin ) = Let qI and qII be two unit quaternions (7). The operator
2 2
β β β Rq (p)I is first applied to the vector p. Then we apply the
= x i cos2 + y j cos2 + z k cos2 + operator Rq (p)II and obtain the operator Rq (p)I, II . Equiva-
2 2 2
β β β β lently, the composition RqI ◦ RqII of the two operators can
+ x j i sin cos + y j j sin cos + be applied:
2 2 2 2
β β β β Rq (Rq (p)I ) = qII · (qI p qI ) · qII =
+ z j k sin cos − x i j sin cos −
2 2 2 2
= (qII qI ) · p · (qI qII ) = (17)
β β β β
− y j j sin cos − z k j sin cos − = (qII qI ) · p · (qII qI ) =
2 2 2 2
β β = Rq (p)I, II .
− x j i j sin2 − y j j j sin2 −
2 2
β Because qI and qII are the unit quaternions, same as the
− z j k j sin2 . product qII · qI . Hence the above equation (17) describes
2
3
MATEC Web of Conferences 292, 0 10 60 (2019) https://doi.org/10.1051/matecconf/2019292010 60
CSCC 2019
the rotation operator defining quaternion is the product of 4 Advantages and disadvantages of
the two quaternions qI and qII . The following equation quaternions
describes the operator Rq (p)z y x for three unit quaternions
qz , qy and q x . These quaternions represent the unit quater- In previous sections, one of two principal rotational meth-
nions rotations around the belonging axes x, y and z, re- ods were introduced: one of them is the rotation defined by
spectively, for the general p = x i + y j + z k, p ∈ R3 the quaternions and the other one (not presented in this pa-
per) is defined by the Euler angles represented by the rota-
= (qz qy q x ) · p · (qz qy q x ) =
Rq (p)z y x
tion matrices, method, that is well known. In this section,
γ γ β β we will describe advantages and disadvantages of these
= [(cos + k · sin )(cos + j · sin ) ⊗
2 2 2 2 methods. First, the time quaternions are not so easy to
α α
⊗ (cos + i · sin )] ⊗ (18) be represented mathematically – seem to be complicated.
2 2 The representation of the rotations by the quaternions has
γ γ
⊗ (x i + y j + z k) ⊗ [(cos − k · sin ) ⊗ several advantages over the other possible representation
2 2
β β α α by the Euler angles. The parametrization of the rotations
⊗ (cos − j · sin )(cos − i · sin )]. using the quaternions involve only the angle and the axis
2 2 2 2
of the rotation. In the theory of the quaternions, q and
Compound quaternion: – q correspond to the same rotation. Other advantage of
(qz qy q x ) = this approach is that the quaternion rotation is not influ-
α β γ α β γ enced by the choice of the coordinate system. Further, the
= (cos cos cos + sin sin sin ) + Gimbal lock problem does not appear in the quaternion
2 2 2 2 2 2
α β γ α β γ representation. Overleaf, the Euler angles are easy to un-
+ i (sin cos cos − cos sin sin ) +
2 2 2 2 2 2 derstand and use, compared to the quaternions and matri-
α β γ α β γ ces, so can be a good choice for a user interface. Efficient,
+ j (cos sin cos + sin cos sin ) +
2 2 2 2 2 2 easy to use with only three components, any rotation can
α β γ α β γ be represented. On the other hand, the most discussed dis-
+ k (cos cos sin − sin sin cos ) .
2 2 2 2 2 2 advantage is the Gimbal lock and uniqueness for the Euler
Conjugated compound quaternion: angles calculations, which miss the inverse rotation in the
(qz qy q x ) =
three-dimensional space. In conclusion, the quaternions
offer the best choice for representation of rotations.
α β γ α β γ
= (cos cos cos + sin sin sin ) − Now, an example for a better understanding of this
2 2 2 2 2 2
α β γ α β γ problematic is depicted. For the purpose of simplicity, the
− i (sin cos cos − cos sin sin ) − theory of the quaternions is demonstrated, but only around
2 2 2 2 2 2
α β γ α β γ the z-axis by γ angle. The calculations are performed with
− j (cos sin cos + sin cos sin ) − a respect to the presented theory and the mathematical no-
2 2 2 2 2 2
α β γ α β γ tation. Let have two points, for example, B (200; 0; 0)
− k (cos cos sin − sin sin cos ) .
2 2 2 2 2 2 and C (100; 100; 0) of space. We want to rotate them
The compound and the conjugated compound quaternions by γ = 10, 02895 degrees around the z-axis. New coor-
is put into the relationship for the Rq (p)z y x ; and after the dinates, using the theory of quaternions, are found in the
substitution (19) for a, b, c and d, following is obtained: Figure 2.
α β γ α β γ
a = (sin cos cos − cos sin sin ),
2 2 2 2 2 2
α β γ α β γ
b = (cos sin cos + sin cos sin ), (19)
2 2 2 2 2 2
α β γ α β γ
c = (cos cos sin − sin sin cos ),
2 2 2 2 2 2
α β γ α β γ
d = (cos cos cos + sin sin sin ).
2 2 2 2 2 2
Then the general operator of the quaternion rotation is in
the form:
x(a2 − b2 − c2 + d2 )+
Rq (p)z y x = i +2y(a · b − c · d)+ +
+2z(b · d + a · c)
2x(a · b + c · d)+
+ j +y(−a2 + b2 − c2 + d2 )+ + (20)
+2z(b · c − a · d)
2x(a · c − b · d)+
+ k +2y(b · c + a · d)+ .
Figure 2. Quaternion rotation around the z-axis rotation by γ
+z(−a − b + c + d )
2 2 2 2 angle.
4
MATEC Web of Conferences 292, 0 10 60 (2019) https://doi.org/10.1051/matecconf/2019292010 60
CSCC 2019
References [9] Y. B. Jia, Com S 15, (2013)
[10] J. Vince,Quaternions for Computer Graphics
[1] A. Watt, M. Watt, Advanced Animation and Rendering (Springer, 2011)
Techniques(ACM Press, San Francisco, 1992) [11] B. Witten, J. Shragge, SEG, (2006) J. Diebel, Matrix
[2] L. Perumal, IJETI, 1, 35 − 52, (2011) 16, 1 − 35, (2006)
[3] L. Vicci, UNC, (2001) [12] S. Zomorodi,Quaternions Approach in Studying
[4] B. K. P. Horn, JOSA 4, 629 − 642 (1987) Rotation. Available from:
[5] E. B Dam, M. Koch, M. Lillholm, Quaternions, In- < https : //www.academia.edu/32250200/Quaternions
terpolation and Animation (UCP,Copenhagen Press, ApproachinS tudyingR otation?auto = download >
1998) [13] J. G. Campbell,Notes on Mathematics for 2D and
[6] W. R. Hamilton, Pilosophical Magazine and Journal 3D Graphics. Available from:
of Science 3, 489 − 495, (1844) < http : //www. jgcampbell.com/msc2d3d/grmaths.pd f >
[7] J. B. Kuipers, Quaternions and Rotation Sequences [14] B. Saleh, Computer GraphicsFundamental: 2D and
(Princeton University Press, 1999) 3D Affine Transformations. Available from:
[8] M. Ben-Ari, A Tutorial on Euler Angles < https : //s3.amazonaws.com/academia.edu.documents
and Quaternions. Available from: < http : /53228060/CG2 Da nd3 DA f f ineT rans f ormation.pd f ?AW
//www.weizmann.ac.il/sci − tea/benari/sites/sci − S AccessKeyIdAKIAIWOWYYGZ2Y53UL3AExpires155
tea.benari/ f iles/uploads/ 9638120qgQS 4aOXi38S RT z5pRKS KUzPv2B43Drespo
so f twareAndLearningMaterials/quaternion − nsecontentdispositioninline3B20 f ilename3DComputergr
tutorial − 2 − 0 − 1.pd f > aphics2Dand3DA f f ineT rans.pd f >