Slerp
Slerp, short for spherical linear interpolation, is a geometric algorithm that computes an interpolated value between two unit quaternions by traversing the shortest path (great circle arc) on the unit sphere at a constant angular velocity, ensuring smooth and natural rotational transitions in three-dimensional space.[1]
Introduced by Ken Shoemake in his seminal 1985 paper "Animating Rotation with Quaternion Curves," slerp was developed to enable the creation of spline curves on the quaternion hypersphere for interpolating sequences of arbitrary rotations in computer animation.[2] Unlike linear interpolation, which can produce uneven motion or distortions when applied directly to rotation representations, slerp maintains uniform angular speed and avoids issues like gimbal lock inherent in Euler angle methods.[2]
The technique has become a cornerstone in computer graphics and related fields, powering rotation animations in video games, film production, and simulation software by providing efficient, high-quality interpolation for object orientations and camera paths.[3] It is implemented in numerous mathematical libraries and engines, such as SciPy for scientific computing and Apache Commons for general quaternion operations, highlighting its versatility beyond animation to areas like robotics and virtual reality.[4][5]
Introduction
Definition and Motivation
Spherical linear interpolation (SLERP) is a geometric interpolation technique that computes a path between two points on the unit sphere by following the geodesic, or great circle, connecting them, thereby ensuring a constant angular velocity along the trajectory. Introduced in the context of computer graphics, SLERP produces smooth, uniform-speed transitions on the spherical manifold, making it particularly suitable for representing continuous changes in orientation or direction.
The primary motivation for SLERP arises from the limitations of linear interpolation in non-Euclidean spaces such as spheres, where rotations and orientations are naturally embedded. Linear methods, such as linearly interpolating Euler angles or rotation matrices, often distort angular distances, result in uneven speeds—accelerating midway through the path—and introduce singularities like gimbal lock, leading to abrupt or unnatural motions. In contrast, SLERP maintains the intrinsic geometry of the sphere, preserving angular uniformity and avoiding these artifacts to enable more realistic and computationally stable animations.[6]
A basic intuitive example involves transitioning between two 3D orientations, such as shifting a camera's viewpoint from one direction to another in a virtual scene; SLERP generates a fluid arc along the sphere without erratic twisting or speed variations that would occur with linear approaches. Quaternions serve as an effective representation for these rotations due to their compactness and lack of singularities, allowing SLERP to operate directly on them for efficient computation.
Historical Context
The concept of spherical linear interpolation, known as SLERP, was coined by Ken Shoemake in 1985 while developing rotation tools for computer graphics software at The Singer Company's Link Flight Simulation Division.[2] Shoemake introduced SLERP to enable smooth interpolation of 3D rotations, addressing the challenges of animating rigid body motions and camera movements that traditional Euler angle representations could not handle effectively.[6]
SLERP was first formalized in Shoemake's seminal SIGGRAPH paper, "Animating Rotation with Quaternion Curves," presented at the 12th annual Conference on Computer Graphics and Interactive Techniques in 1985.[2] In this work, SLERP was defined for unit quaternions to interpolate along the shortest path (great circle) on the unit sphere, ensuring constant angular velocity and avoiding singularities.[6] The method built on earlier mathematical foundations, including William Rowan Hamilton's invention of quaternions in 1843 for describing rotations and Arthur Cayley's subsequent developments in the 1840s.[6]
The roots of SLERP's geometric principle—interpolation along great circles—lie in 19th-century differential geometry, where concepts of geodesics on curved surfaces, including spheres, were formalized by mathematicians such as Carl Friedrich Gauss and Bernhard Riemann.[7]
Following its introduction, SLERP saw rapid integration into professional graphics tools. Its influence persists in contemporary libraries, such as the OpenGL Mathematics (GLM) C++ library, which implements quaternion SLERP via its mix function to facilitate efficient rotation blending in graphics applications.[8]
Mathematical Foundations
Spherical Geometry Essentials
In spherical geometry, points on the unit sphere are represented as unit vectors in three-dimensional Euclidean space, where the sphere serves as a model for directions or orientations with radius one centered at the origin.[9] These points satisfy the condition \|\mathbf{v}\| = 1, ensuring they lie on the surface without scaling distortions.[9]
The shortest paths connecting two such points are geodesics, which trace great circles on the sphere—intersections of the sphere with planes passing through its center.[10] Great circles represent the analogs of straight lines in Euclidean geometry, providing the minimal-distance routes that preserve the intrinsic metric of the spherical surface.[10]
The angular separation \theta between two points \mathbf{a} and \mathbf{b} on the unit sphere is computed using the dot product formula:
\cos \theta = \mathbf{a} \cdot \mathbf{b}
This relation directly yields the central angle subtended at the sphere's center, enabling precise measurement of geodesic distances as \theta radians (or scaled by the radius for general spheres).[10][9]
For effective interpolation between points, a uniform parameterization along the great circle arc is essential, ensuring constant angular speed to prevent artifacts like varying acceleration in animations or simulations.[11] Such constant-speed traversal maintains smooth motion proportional to the interpolation parameter.[11]
SLERP paths adhere to these great circle arcs, inherently preserving geodesic distances between endpoints and minimizing geometric distortion during interpolation.[11] This property ensures that interpolated points remain on the sphere while following the most direct route, avoiding unnecessary deviations that could arise from linear approximations in ambient space.[11]
Quaternions for Rotations
Quaternions, introduced by William Rowan Hamilton in 1843, extend complex numbers to four dimensions and serve as an effective algebraic structure for representing rotations in three-dimensional space.[12] A quaternion is expressed as q = w + x i + y j + z k, where w, x, y, z are real numbers, and i, j, k are imaginary units satisfying i^2 = j^2 = k^2 = ijk = -1.[13]
For rotations, unit quaternions with norm \|q\| = \sqrt{w^2 + x^2 + y^2 + z^2} = 1 are used, as they form a double cover of the special orthogonal group SO(3) and parameterize orientations without singularities.[13] These unit quaternions lie on the three-dimensional unit sphere in four-dimensional space, enabling a geometrically intuitive approach to rotation composition.[14]
The rotation of a three-dimensional vector \mathbf{v} by a unit quaternion q is given by the conjugation formula \mathbf{v}' = q \mathbf{v} q^{-1}, where \mathbf{v} is treated as a pure quaternion $0 + v_x i + v_y j + v_z k, and q^{-1} is the conjugate \overline{q} = w - x i - y j - z k since \|q\| = 1.[13] This formulation adapts Rodrigues' rotation formula, expressing the rotated vector as
\mathbf{v}' = \cos\theta \cdot \mathbf{v} + (1 - \cos\theta) (\mathbf{u} \cdot \mathbf{v}) \mathbf{u} + \sin\theta \cdot (\mathbf{u} \times \mathbf{v}),
where q = \cos(\theta/2) + \sin(\theta/2) (u_x i + u_y j + u_z k) with \mathbf{u} as the unit rotation axis and \theta the angle.[13]
Compared to Euler angles, which parameterize rotations using three sequential angles about fixed or body axes, quaternions avoid gimbal lock—a degeneracy where intermediate axes align, losing a degree of freedom (e.g., at pitch angles of ±90°).[14] Additionally, the spherical geometry of unit quaternions facilitates smooth interpolation between orientations by traversing great-circle paths on the unit sphere.[14]
To ensure a quaternion represents a pure rotation, it must be normalized by dividing by its norm: q_{\text{unit}} = q / \|q\|.[14] Non-unit quaternions may introduce scaling effects, so normalization is essential after operations like addition or multiplication that could alter the magnitude.[13]
Core Algorithms
Geometric SLERP
Geometric spherical linear interpolation (SLERP) provides a method for interpolating between two unit vectors \mathbf{a} and \mathbf{b} on the surface of a unit sphere, ensuring the path follows a great circle arc at constant angular velocity. This approach is essential for applications requiring smooth transitions along spherical geodesics, such as direction mapping or orientation blending in vector spaces. Unlike linear interpolation, which may produce paths that deviate from the sphere, SLERP maintains the interpolated points on the unit sphere.[6]
The derivation begins with the angular bisector concept in spherical geometry. Given two unit vectors \mathbf{a} and \mathbf{b}, the angle \theta between them is computed as \theta = \arccos(\mathbf{a} \cdot \mathbf{b}). To achieve constant angular speed along the great circle, the interpolation weights are derived using sine functions, which arise from the spherical law of sines applied to the geodesic triangle formed by the origin, \mathbf{a}, and \mathbf{b}. The resulting formula is:
\text{slerp}(\mathbf{a}, \mathbf{b}, t) = \frac{\sin((1-t)\theta)}{\sin \theta} \mathbf{a} + \frac{\sin(t \theta)}{\sin \theta} \mathbf{b}
for t \in [0, 1]. This weighted sum ensures the output is a unit vector lying in the plane spanned by \mathbf{a} and \mathbf{b}, tracing the shorter arc when \theta \leq \pi. The sine normalization guarantees that the interpolation parameter t corresponds directly to the fraction of the angular distance traveled.[6]
Geometrically, the SLERP result resides on the great circle defined by the plane through the origin, \mathbf{a}, and \mathbf{b}, providing the shortest path on the sphere between the endpoints. This preserves the spherical metric, avoiding distortions from planar projections.[6]
Special cases require careful handling to avoid numerical issues. When \theta \approx 0 (vectors nearly aligned), \sin \theta \approx 0, leading to division by zero; in such instances, SLERP falls back to linear interpolation: \text{lerp}(\mathbf{a}, \mathbf{b}, t) = (1-t)\mathbf{a} + t\mathbf{b}, normalized if necessary. For antipodal points where \theta = \pi (\mathbf{a} \cdot \mathbf{b} = -1), the path is ambiguous, as infinitely many great circles connect the points; SLERP is undefined here, and alternative methods, such as selecting a specific plane or using normalized linear interpolation, must be employed based on context.[6][15]
The following pseudocode outlines the step-by-step computation:
function slerp(a, b, t):
dot = a · b
if dot > 0.9995: // θ ≈ 0
return normalize((1 - t) * a + t * b)
theta = acos([clamp](/page/Clamp)(dot, -1, 1))
if theta == π: // antipodal, handle specially (e.g., fallback)
return normalize((1 - t) * a + t * b)
sin_theta = sin(theta)
coeff_a = sin((1 - t) * theta) / sin_theta
coeff_b = sin(t * theta) / sin_theta
return normalize(coeff_a * a + coeff_b * b)
function slerp(a, b, t):
dot = a · b
if dot > 0.9995: // θ ≈ 0
return normalize((1 - t) * a + t * b)
theta = acos([clamp](/page/Clamp)(dot, -1, 1))
if theta == π: // antipodal, handle specially (e.g., fallback)
return normalize((1 - t) * a + t * b)
sin_theta = sin(theta)
coeff_a = sin((1 - t) * theta) / sin_theta
coeff_b = sin(t * theta) / sin_theta
return normalize(coeff_a * a + coeff_b * b)
This implementation includes clamping for numerical stability in the acos computation and normalization to ensure unit length, though the formula theoretically preserves it.[6]
Quaternion SLERP
Quaternion spherical linear interpolation (SLERP) adapts the geometric SLERP to unit quaternions for smooth rotation interpolation, ensuring constant angular velocity along the great circle arc on the unit quaternion hypersphere.[6] The standard formula is given by
\text{slerp}(q_1, q_2, t) = \frac{\sin((1-t)\theta)}{\sin \theta} \, q_1 + \frac{\sin(t \theta)}{\sin \theta} \, q_2,
where t \in [0, 1], \theta = \arccos(q_1 \cdot q_2), and the result is renormalized to unit length.[6] This weighted sum of the input quaternions produces intermediate orientations that avoid the singularities of Euler angles and provide uniform motion in angular space, making it ideal for keyframe animation in computer graphics.[6]
A key consideration in quaternion SLERP is the double-cover property, where q and -q encode the same rotation due to the projective nature of the rotation group SO(3).[6] To ensure the shortest interpolation path and prevent discontinuities, the dot product q_1 \cdot q_2 is adjusted by negating q_2 if it is negative, guaranteeing \theta \leq \pi/2 and selecting the representative closest to q_1.[16] In sequential interpolations, such as animation curves, this sign adjustment is applied relative to the previous quaternion to maintain smoothness.[6]
For improved numerical stability, particularly when \theta is small (near 0, causing division by near-zero \sin \theta) or in iterative computations, the logarithmic form of SLERP is often preferred: \text{slerp}(q_1, q_2, t) = q_1 \cdot \exp\left( t \cdot \log(q_2 \cdot q_1^{-1}) \right), where \log and \exp are the quaternion logarithm and exponential maps, and q_1^{-1} is the conjugate for unit quaternions.[14] This exponentiation-based approach avoids trigonometric function instabilities by operating in the Lie algebra, reducing cancellation errors and enabling efficient repeated evaluations without recomputing \theta.[14] Computationally, the standard formula's reliance on \arccos can be sidestepped in loops by approximating \theta via \atantwo(\sqrt{1 - (q_1 \cdot q_2)^2}, q_1 \cdot q_2) for better handling of the full angular range, or by polynomial approximations to eliminate transcendentals altogether.[16]
Applications and Variants
Use in Computer Graphics
In computer graphics, SLERP plays a crucial role in animation by enabling keyframe interpolation for object rotations, particularly in tools like Unity where the Quaternion.Slerp function produces transitions with constant angular speed, avoiding the uneven pacing of linear methods. This approach ensures natural-looking motion for characters and objects, as rotations follow the shortest path on the unit sphere without singularities like gimbal lock. Introduced in seminal work on quaternion-based animation, SLERP has become a standard for blending orientations in real-time applications.[6]
SLERP is also integral to camera path generation in games and simulations, where it facilitates smooth fly-throughs by interpolating camera orientations along geodesic arcs, eliminating the abrupt shifts that occur with linear interpolation of rotation matrices. For instance, in dynamic scenes like virtual tours or first-person navigation, this results in immersive, fluid camera movements that maintain consistent rotational velocity. The quaternion SLERP method is predominantly used here for its ability to handle complex 3D orientations efficiently.[6]
In lighting and shading pipelines, SLERP supports the interpolation of normal vectors—unit directions on spherical surfaces—to avoid distortions from linear methods. This spherical approach outperforms linear interpolation for directions, preserving vector lengths and preventing distortions in shading calculations across hemispheres or globes.[17]
Performance-wise, SLERP is suitable for shader environments like GLSL in real-time rendering, as quaternions provide a compact representation for rotations compared to matrices, avoiding the need for full matrix conversions in graphics engines.[6][18]
Extensions and Alternatives
Squad, or spherical quadrangle interpolation, extends SLERP by enabling C1-continuous curves through a double application of SLERP, incorporating intermediate control quaternions to achieve smoother transitions between multiple orientations.[14] This method, introduced by Ken Shoemake, constructs a cubic-like interpolation on the quaternion sphere by first blending to an intermediate quaternion and then to the target, ensuring tangent continuity for animation paths.[6]
An alternative to SLERP is normalized linear interpolation (NLERP), which performs a linear blend between two quaternions followed by renormalization to the unit sphere, offering computational simplicity at the cost of reduced accuracy in angular velocity compared to SLERP's constant-speed geodesic path.[19] While faster due to avoiding trigonometric functions, NLERP approximates the great-circle arc less precisely, particularly for larger angles, making it suitable for real-time applications where performance outweighs exact sphericity.[19]
SLERP is limited to interpolating along the shortest great-circle arc, which may not align with intuitive paths for arcs exceeding 180 degrees, potentially leading to unexpected rotations in sequences; for higher-order continuity in splines, alternatives like the de Casteljau algorithm adapted to the sphere replace linear steps with SLERP operations to generate smooth spherical Bézier curves.[20] This spherical de Casteljau method supports arbitrary-degree interpolants on the unit sphere, addressing SLERP's piecewise nature for complex trajectories.[6]
Modern implementations of SLERP appear in libraries such as Eigen for quaternion operations. Recent extensions include dual-quaternion-based SLERP for interpolating combined rotations and translations, applied in robotics and autonomous vehicle path planning as of 2023.[21]