Dual Quaternions
Dual Quaternions
Dual-Quaternions
From Classical Mechanics to Computer Graphics and Beyond
Ben Kenwright
www.xbdev.net
[email protected]
Abstract
This paper presents an overview of the analytical advantages of dual-quaternions and their potential in the areas of robotics,
graphics, and animation. While quaternions have proven themselves as providing an unambiguous, un-cumbersome,
computationally efficient method of representing rotational information, we hope after reading this paper the reader will
take a parallel view on dual-quaternions. Despite the fact that the most popular method of describing rigid transforms is
with homogeneous transformation matrices they can suffer from several downsides in comparison to dual-quaternions. For
example, dual-quaternions offer increased computational efficiency, reduced overhead, and coordinate invariance. We also
demonstrate and explain how, dual-quaternions can be used to generate constant smooth interpolation between transforms.
Hence, this paper aims to provide a comprehensive step-by-step explanation of dual-quaternions, and it comprising parts
(i.e., quaternions and dual-numbers) in a straightforward approach using practical real-world examples and uncomplicated
implementation information. While there is a large amount of literature on the theoretical aspects of dual-quaternions there
is little on the practical details. So, while giving a clear no-nonsense introduction to the theory, this paper also explains and
demonstrates numerous workable aspect using real-world examples with statistical results that illustrate the power and
potential of dual-quaternions.
Basically, a dual-quaternion is the concatenation of it is essential to have a good understand of its underpinned
quaternion and dual-number theory (see Figure 1). parts work (i.e., quaternions and dual-numbers).
Furthermore, once the reader understands how quaternions
Quaternion Dual-Number
Mathematics Dual-Quaternions work, it should be trouble-free and straightforward to see
Theory how dual-quaternions operate due to their likeness.
Figure 1: Dual-Quaternions Components. A quaternion is represented by two fundamental parts, a
To avoid confusion and enable the reader to easily scalar real part (w) and an imaginary vector part (
distinguish a quaternion from a dual-quaternion we use v x, y, z ). In practice we are only concerned with a unit-
two discernible symbols to identify them (see Equation 1). quaternion since they offer the most benefits and represent
the rotation on a 4D unit-hypersphere. While the majority
Quaternion (q) of people are familiar with the decomposition and
1
Dual Quaternion ( ) principles of quaternions, there can, however, be a
deficiency in the practical considerations.
Quaternion
Real Complex
q = w + ix + jy + kz
Imaginary 4 scalar variables
= qr + qd
Dual-Operator
8 scalar variables
Figure 2: Visual Overview of Quaternion and Dual-Quaternion Components.
In practice, if you do decide to convert to the axis-angle q0 q1 (q0w q1w , q0 x q1x , q0 y q1y , q0 z q1z ) 8
representation, you should ensure the quaternion is always
a unit-quaternion and be aware of the divide by zero
Quaternion Multiplication
causality that may occur (i.e., sin is zero).
2 Quaternion multiplication is analogous to matrix
multiplication; whereby, multiplying quaternions together
Quaternion Vector Transformation is equivalent to combining their transforms. For example,
when two quaternions are multiplied together it is
The quaternions transformation can be applied to a 3D
equivalent to the first quaternion being rotated by the axis
vector coordinate by means of multiplication. Whereby, to
and angle of the second quaternion. However, quaternion
transform a vector position by a quaternion we simply
multiplication is non-commutative (i.e., order of
convert the vector to a quaternion (i.e., the imaginary part
multiplication matters) but can be simplified by being
is the vector position, and the scalar real part zero) and
represented using the dot and cross product (shown in
multiply it by the quaternion transform and its conjugate,
Equation 9).
as shown in Equation 5. Optionally, we can convert the
quaternion transform to a matrix with little or no extra q0 q1 (qw0 q v 0 )(qw1 q v1 )
work for systems that operate with matrices (e.g., 9
(qw0 qw1 q v 0 q v1 ) (qw0q v1 qw1q v 0 q v 0 q v1 )
transforms are done on the GPU using matrices).
ˆ ˆ 1
p ' qpq 5
where qw0 and qw1 represent the real scalar components of
where each quaternion and, q v 0 and q v1 represent the vector
q̂ is a unit-quaternion representing the rotation component of each quaternion.
transform
Quaternion Difference
q̂ 1 is a unit-quaternion that represents the inverse Since each quaternion represents an axis-angle, then
of the rotation quaternion multiplying two quaternions together is equivalent to
p is the 3D vector point in quaternion form (i.e., transforming one quaternion by another. Hence, it should
p (0, v) with v (vx , vy , vz ) ) be obvious, that we can use this to determine differences
between quaternions. If both quaternions are the same, and
p ' is the 3D transformed vector point in we multiply one by the inverse of itself, it will cancel out
quaternion form (i.e., p ' (0, v) ) (see Equation 10) and give us an identity quaternion.
However, it is extremely important to note that for a unit- ˆ ˆ 1 1
qq 10
quaternion the inverse is the same as the conjugate. This is
due to the mathematical and computational efficiency by So if we have two quaternions, we simply multiply one by
which the conjugate is calculated. The conjugate of a the inverse to get the difference between them (Equation
quaternion is simply the negation of the vector component 11). It is vital to remember that the inverse of a unit-
(shown in Equation 6). quaternion is the same as the conjugate.
= (0 - n) = -n, which is analogous to what we calculated in developed and what we primarily make use of in this paper
the example. is the screw calculus that allows the unification of
translation and rotation.
Quaternion Spherical Linear Interpolation (SLERP) The definition and properties of a dual-number are given in
Quaternion spherical linear interpolation is the Equation 18. Dual-numbers are akin to complex numbers.
transformation along the surface of the 4D unit- However, whereas complex numbers have a real-part and
hypersphere. an imaginary-part and dual-numbers have a real-part and a
Starting with the well known exponential function from dual-part.
complex numbers it can be shown that in Equation 13.
z r d with 2 0 but 0 18
e cos i sin
i
13
where is known as the dual-operator, r is the real-part
Then we can equate our quaternion and represent it as an and, d the dual-part.
exponential given by Equation 14.
Dual-Number Addition
q ev cos v sin 14
(rA d A ) (rB d B ) (rA rB ) (d A d B ) 19
where and v is a unit vector (noting that v 2 1 ).
2 Dual-Number Multiplication
We can then write the quaternion in the form (Equation (rA d A ) (rB d B ) rA rB rA d B rB d A 2 d A d B
qt cos(t) vˆ sin(t) 15
Dual-Number Division
Then the Slerp expression is given by Equation 16.
(rA d A ) (rA d A ) (rB d B )
SLERP(q0 , q1 : t ) q0 (q01q1 )t 16 (rB d B ) (rB d B ) (rB d B )
For example, let us consider two very simple cases when rA rB (rB d A rA d B )
21
t=0 and t=1 (rB ) 2
t 0 rA rB rB d A rA d B
q cos(t ) v sin(t )
t rB 2 rB 2
q 0 cos(0) v sin(0)
Dual-Number Differentiation
q0 1
From elementary calculus principles shown in Equation
q0 (q0 1q1 )t q0 (q0 1q1 )0 q0 (1) q0 22.
and d s ( x x ) s( x )
t 1 s( x) lim 22
dx x 0 x
q t cos(t ) v sin(t ) We use Taylor series to find the differentiable (Equation
q1 cos() v sin() 23).
q0 (q0 1q1 )t q0 (q0 1q1 )1 (q0 q0 1 )q1 (1)q1 q1 f (rA d A ) f (rA )
f (rA )
d A
f (rA )
( d A ) 2
f (rA )
(d A )3 ...
1! 2! 3!
f (rA )
f (rA ) d A 0 0 .... (as, 2 0) 23
An alternative, and more popular, representation of 1!
Equation 16 can be calculated using a geometric approach f (rA ) f (rA )d A
efficient system for solving otherwise complex problems. quaternion that possesses both the translation and rotation
For example, we can represent a rigid transforms with components; however, be aware that the multiplication
eight scalar variables; we can combine transforms order is important.
effortlessly through concatenation, and we are able to
produce smooth constant interpolation between rigid Dual-Quaternion to Position and Rotation
transformations. As shown in Figure 2, the dual- We can extract the position and rotation from a dual-
quaternion is decomposed into two parts the real part and quaternion. In reverse to Equation 25 that created a dual-
the dual-part. quaternion from a position and rotation, we conversely
extract the position and rotation using Equation 29.
Dual-Quaternion Identity
The identity of a dual-quaternion is shown in Equation 24 qr q d
and is analogous to a quaternion identity. Therefore, any r qr 29
dual-quaternion that is multiplied with an identity dual- t 2 qd qr *
A q0 q1
r [cos( ), n x sin( ), n y sin( ), n z sin( ) ]
2 2 2 2 26 B q2 q3
31
t [0, t x , t y , t z ] A B (q0 q1 )(q2 q3 )
q0 q2 (q0 q3 q1q2 )
|| ˆ || ||
ˆˆ* || 1 34 dual quaternion screw parameters
2 cos 1 ( wr )
Dual-Quaternion Vector Transformation 1
d 2 wd
Equivalent to a quaternion a dual-quaternion can transform vr vr
a 3D vector coordinate as shown in Equation 34. Note that 37
for a unit-quaternion the inverse is the same as the 1
l vr
conjugate. v v
r r
p ' ˆ pˆ 1 35 d wr 1
m vd l
where 2 v r v r
is a dual-quaternion representing the transform and
is a dual-quaternion that is the inverse of the dual-
1
screw parameters dual quaternion
quaternion
p is a dual-quaternion representing the rigid wr cos
2
transform (e.g., 3D vector point
p (1,0,0,0) (0, vx , vy vz ) ) v r l sin
2 38
p ' is a dual-quaternion with the resulting transform. d
wd sin
Plücker Coordinates
2 2
d
Plücker coordinates [12] are used to create Screw v d sin m cos l
coordinates which are an essential technique of
2 2 2
representing lines. We need the Screw coordinates so that
we can re-write dual-quaternions in a more elegant form to Dual-Quaternion Power
aid us in formulating a neater and less complex
We can write the dual-quaternion representation in the
interpolation method that is comparable with spherical
form given in Equation 39 (see Daniilidis [14] for details).
linear interpolation for classical quaternions.
The Definition of Plücker Coordinates: d d
ˆ cos ( l m) sin
1. p is a point anywhere on a given line 2 2
39
2. l is the direction vector ˆ ˆ
cos vˆ sin
3. m = p l is the moment vector 2 2
4. ( l , m) are the six Plücker coordinate where
We can convert the eight dual-quaternions parameters to ˆ is a unit dual-quaternion
an equivalent set of eight screw coordinates and vice-versa.
The definition of the parameters are given in Equation 36. v̂ is a unit dual-vector vˆ l m
ˆ is a dual-angle ˆ d
screw parameters ( , d , l , m)
The dual-quaternion in this form is exceptionally
dual quaternion qr qd 36 interesting and valuable as it allows us to calculate a dual-
( wr v r ) ( wd v d ) quaternion to a power. Calculating a dual-quaternion to a
power is essential for us to be able to easily calculate
where in addition to l representing the vector line direction spherical linear interpolation. However, instead of purely
and m the line moment, we also have d representing the rotation as with classical quaternions, we are instead now
translation along the axis (i.e., pitch) and the angle of able to interpolate full rigid transformations (i.e., rotation
rotation . and translation) by using dual-quaternions.
Converting to and from a dual-quaternion and its screw ˆ ˆ
parameters is shown in Equation 37 and Equation 38 (see ˆt cos t vˆ sin t 40
Daniilidis [13] for details). 2 2
quaternion SLERP we use the power function to calculate (For example, see Listing 1 for a practical implementation
the interpolation values for ScLERP shown in Equation 41. example).
Transform Transform
A B
Transform Transform
A A
Transform Transform
B B
Linear Dual-Quaternion
Figure 3: Visual comparison between linear and dual-quaternion weighting for vertex skinning.
LERP(a, b : t ) b (a b)t 43
greater than then the interpolation will take the "longest
2
where a and b represent the start and end value and t the path". We can detected easily in practice by taking the dot
in-between ratio. produce of the two quaternions (for a dual-quaternion we
In fact, for small changes we can use Equation 43 to use the quaternion for the rotation). If the dot product is
interpolate between quaternions and dual-quaternions. less than zero then the longest path will be taken.
However, as the quaternion and dual-quaternion become However, if we want to prevent the longest path from
more dissimilar there is a greater error and the intermediate being taken we simply negate all the elements for the
steps become less smooth and less correct. The quaternion or dual-quaternion before interpolating.
intermediate steps between the start and end do not Likewise, if we desire the longest path we can check that
represent a unit-quaternion rotation or dual-quaternion the dot product is greater than zero before negating the
rotation. Hence, we need to re-normalize the value at each quaternion or dual-quaternion.
step to ensure it falls on the unit-hypersphere. Most
importantly, though, is that the interpolation rate is not
Catmull-Rom Spline-Based Interpolation
constant. We can reduce the error and make the linear For irregular spaced key-frame data, we can exploit the
interpolation approximation more tolerable by normalizing Catmull-Rom spline-based vector interpolation function
the values between steps. This is known as Normalized and dual-quaternions algebra as a method for generating a
Linear Interpolation (NLERP) and has the added advantage unified, smooth, continuous trajectory path.
of ensuring that the intermediate values are always of unit-
length (see Equation 44). Again, it should be stressed that
Eradication of the Square Root
the linear interpolation approximation is only suitable for We can optimize some operations by eradicating the
small changes. square root overhead. Since both quaternions and dual-
quaternions are normalized the same way as vectors (see
qA + (qB - qA )t Equation 45), we can identify cases whereby an element is
NLERP(q A , qB : t ) 44
|| qA + (qB - qA )t || multiplication with another element to cancel out the
square root.
where a is the start, b is the end and t is the interpolation
q q
amount (i.e., 0.0 to 1.0). qˆ 45
While it has numerous problems for both quaternions and || q || qq
dual-quaternions, it is computationally fast and easy to
However, the multiplication of two quaternion elements
implement and can, however, give reasonably good
results in the square root being redundant. For example,
approximations for small interpolations. The trouble is,
when we construct a matrix from a quaternion (as shown in
quaternions and dual-quaternions do not travel along
Equation 7) we multiply pairs of elements. This can be
straight-line trajectories. However, we can use an
used to cancel out the necessity to normalize the result as
alternative interpolation method that follows the unit-
shown in Equation 46.
hypersphere sphere. This is accomplished by interpolation
along the unit-hypersphere to produce a constant and qx qy qx q y
smooth rate of change. Dual-quaternions can use the qˆ x qˆ y 46
qq qq qq
exponential representation similar to quaternions to
generate an interpolation scheme to produce constant
smooth interpolation. Performance Comparison
It can be shown without difficulty that in general a dual-
Shortest or Longest Interpolation Path quaternion takes less operations to compute a general
Contrary to popular belief, a quaternion and dual- transform concatenation compared to a matrix (see Table
quaternion by default will not take the shortest path 1).
between points when interpolated. This is because a
quaternion can represent the same orientation using two Matrix4x4 : 64mult + 48adds
different representations, and consequently a dual- Matrix4x3 : 48mult + 32adds
quaternion. This means that both quaternions and dual- DualQuaternion : 42mult + 38adds
quaternions do not offer a unique representation of an Table 1: Computational cost of combining matrices and
orientation or transformation (i.e., there are two). The dual-quaternions.
difference between the two representation becomes
Furthermore, for rigid skeletal animations, the computation
apparent during interpolation and provide a method for
of world space transforms in addition to the overhead cost
determining the shortest or longest path to be taken during
of transferring the data to the graphics processing unit
interpolation.
(GPU) can be noticeably better. For example, to transfer
The interpolation direction can be calculated by examining the transforms to the GPU each frame a dual-quaternions
the angle between the two transforms. If the angle requires only eight floats compared to a 3x4 matrix that
between the two quaternions (or dual-quaternions) is requires twelve per joint.
Appendix
Sample Dual-Quaternion Class Implementation
public class DualQuaternion_c
{
public Quaternion m_real;
public Quaternion m_dual;
public DualQuaternion_c()
{
m_real = new Quaternion(0,0,0,1);
m_dual = new Quaternion(0,0,0,0);
}
public DualQuaternion_c( Quaternion r, Quaternion d )
{
m_real = Quaternion.Normalize( r );
m_dual = d;
}
public DualQuaternion_c( Quaternion r, Vector3 t )
{
m_real = Quaternion.Normalize( r );
m_dual = ( new Quaternion( t, 0 ) * m_real ) * 0.5f;
}
public static float Dot( DualQuaternion_c a, DualQuaternion_c b )
{
return Quaternion.Dot( a.m_real, b.m_real );
}
public static DualQuaternion_c operator* (DualQuaternion_c q, float scale)
{
DualQuaternion_c ret = q;
ret.m_real *= scale;
ret.m_dual *= scale;
return ret;
}
public static DualQuaternion_c Normalize( DualQuaternion_c q )
{
float mag = Quaternion.Dot( q.m_real, q.m_real );
Debug_c.Assert( mag > 0.000001f );
DualQuaternion_c ret = q;
ret.m_real *= 1.0f / mag;
ret.m_dual *= 1.0f / mag;
return ret;
}
public static DualQuaternion_c operator +(DualQuaternion_c lhs, DualQuaternion_c rhs)
{
return new DualQuaternion_c(lhs.m_real + rhs.m_real, lhs.m_dual + rhs.m_dual);
}
// Multiplication order - left to right
public static DualQuaternion_c operator *(DualQuaternion_c lhs, DualQuaternion_c rhs)
{
lhs = DualQuaternion_c.Normalize( lhs );
rhs = DualQuaternion_c.Normalize( rhs );
Matrix M = Matrix.Identity;
float w = q.m_real.W;
float x = q.m_real.X;
float y = q.m_real.Y;
float z = q.m_real.Z;
public static
DualQuaternion_c ScLERP( DualQuaternion_c from, DualQuaternion_c to, float t )
{
// Shortest path
float dot = Quaternion.Dot(from.m_real, to.m_real);
if ( dot < 0 ) to = to * -1.0f;
// Screw parameters
float angle = 2 * (float)Math.Acos( diff.m_real.W );
float pitch = -2 * diff.m_dual.W * invr;
Vector3 direction = vr * invr;
Vector3 moment = (vd - direction*pitch*diff.m_real.W*0.5f)*invr;
// Exponential power
angle *= t;
pitch *= t;
#if false
public static void SimpleTest()
{
DualQuaternion_c dq0 = new DualQuaternion_c( Quaternion.CreateFromYawPitchRoll(1,2,3),
new Vector3(10,30,90) );
DualQuaternion_c dq1 = new DualQuaternion_c( Quaternion.CreateFromYawPitchRoll(-1,3,2),
new Vector3(30,40,190) );
DualQuaternion_c dq2 = new DualQuaternion_c( Quaternion.CreateFromYawPitchRoll(2,3,1.5f),
new Vector3(5,20,66) );
DualQuaternion_c dq = dq0 * dq1 * dq2;
Listing 1: Dual-Quaternion Implementation Class (note, this version of the class was written for clarity a production ready version
could be optimised and made more compact).