Misplaced Pages

Slerp

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
(Redirected from Spherical linear interpolation) Spherical linear interpolation in computer graphics
This article includes a list of general references, but it lacks sufficient corresponding inline citations. Please help to improve this article by introducing more precise citations. (April 2021) (Learn how and when to remove this message)

In computer graphics, slerp is shorthand for spherical linear interpolation, introduced by Ken Shoemake in the context of quaternion interpolation for the purpose of animating 3D rotation. It refers to constant-speed motion along a unit-radius great circle arc, given the ends and an interpolation parameter between 0 and 1.

Geometric slerp

Slerp has a geometric formula independent of quaternions, and independent of the dimension of the space in which the arc is embedded. This formula, a symmetric weighted sum credited to Glenn Davis, is based on the fact that any point on the curve must be a linear combination of the ends. Let p0 and p1 be the first and last points of the arc, and let t be the parameter, 0 ≤ t ≤ 1. Compute Ω as the angle subtended by the arc, so that cos Ω = p0p1, the n-dimensional dot product of the unit vectors from the origin to the ends. The geometric formula is then

slerp ( p 0 , p 1 ; t ) = sin [ ( 1 t ) Ω ] sin Ω p 0 + sin [ t Ω ] sin Ω p 1 . {\displaystyle \operatorname {slerp} (p_{0},p_{1};t)={\frac {\sin {}{\sin \Omega }}p_{0}+{\frac {\sin}{\sin \Omega }}p_{1}.}

The symmetry lies in the fact that slerp(p0, p1; t) = slerp(p1, p0; 1 − t). In the limit as Ω → 0, this formula reduces to the corresponding symmetric formula for linear interpolation,

lerp ( p 0 , p 1 ; t ) = ( 1 t ) p 0 + t p 1 . {\displaystyle \operatorname {lerp} (p_{0},p_{1};t)=(1-t)p_{0}+tp_{1}.}

A slerp path is, in fact, the spherical geometry equivalent of a path along a line segment in the plane; a great circle is a spherical geodesic.

Oblique vector rectifies to slerp factor.

More familiar than the general slerp formula is the case when the end vectors are perpendicular, in which case the formula is p0cos θ + p1sin θ. Letting θ = tπ/2, and applying the trigonometric identity cos θ = sin(π/2 − θ), this becomes the slerp formula. The factor of 1/sin Ω in the general formula is a normalization, since a vector p1 at an angle of Ω to p0 projects onto the perpendicular ⊥p0 with a length of only sin Ω.

Some special cases of slerp admit more efficient calculation. When a circular arc is to be drawn into a raster image, the preferred method is some variation of Bresenham's circle algorithm. Evaluation at the special parameter values 0 and 1 trivially yields p0 and p1, respectively; and bisection, evaluation at ⁠1/2⁠, simplifies to (p0 + p1)/2, normalized. Another special case, common in animation, is evaluation with fixed ends and equal parametric steps. If pk−1 and pk are two consecutive values, and if c is twice their dot product (constant for all steps), then the next value, pk+1, is the reflection pk+1 = cpkpk−1.

Quaternion slerp

When slerp is applied to unit quaternions, the quaternion path maps to a path through 3D rotations in a standard way. The effect is a rotation with uniform angular velocity around a fixed rotation axis. When the initial end point is the identity quaternion, slerp gives a segment of a one-parameter subgroup of both the Lie group of 3D rotations, SO(3), and its universal covering group of unit quaternions, S. Slerp gives a straightest and shortest path between its quaternion end points, and maps to a rotation through an angle of 2Ω. However, because the covering is double (q and −q map to the same rotation), the rotation path may turn either the "short way" (less than 180°) or the "long way" (more than 180°). Long paths can be prevented by negating one end if the dot product, cos Ω, is negative, thus ensuring that −90° ≤ Ω ≤ 90°.

Slerp also has expressions in terms of quaternion algebra, all using exponentiation. Real powers of a quaternion are defined in terms of the quaternion exponential function, written as e and given by the power series equally familiar from calculus, complex analysis and matrix algebra:

e q = 1 + q + q 2 2 + q 3 6 + + q n n ! + . {\displaystyle e^{q}=1+q+{\frac {q^{2}}{2}}+{\frac {q^{3}}{6}}+\cdots +{\frac {q^{n}}{n!}}+\cdots .}

Writing a unit quaternion q in versor form, cos Ω + v sin Ω, with v a unit 3-vector, and noting that the quaternion square v equals −1 (implying a quaternion version of Euler's formula), we have e = q, and q = cos tΩ + v sin tΩ. The identification of interest is q = q1q0, so that the real part of q is cos Ω, the same as the geometric dot product used above. Here are four equivalent quaternion expressions for slerp.

slerp ( q 0 , q 1 , t ) = q 0 ( q 0 1 q 1 ) t = q 1 ( q 1 1 q 0 ) 1 t = ( q 0 q 1 1 ) 1 t q 1 = ( q 1 q 0 1 ) t q 0 {\displaystyle {\begin{aligned}\operatorname {slerp} (q_{0},q_{1},t)&=q_{0}(q_{0}^{-1}q_{1})^{t}\\&=q_{1}(q_{1}^{-1}q_{0})^{1-t}\\&=(q_{0}q_{1}^{-1})^{1-t}q_{1}\\&=(q_{1}q_{0}^{-1})^{t}q_{0}\end{aligned}}}

The derivative of slerp(q0, q1; t) with respect to t, assuming the ends are fixed, is log(q1q0) times the function value, where the quaternion natural logarithm in this case yields half the 3D angular velocity vector. The initial tangent vector is parallel transported to each tangent along the curve; thus the curve is, indeed, a geodesic.

In the tangent space at any point on a quaternion slerp curve, the inverse of the exponential map transforms the curve into a line segment. Slerp curves not extending through a point fail to transform into lines in that point's tangent space.

Quaternion slerps are commonly used to construct smooth animation curves by mimicking affine constructions like the de Casteljau algorithm for Bézier curves. Since the sphere is not an affine space, familiar properties of affine constructions may fail, though the constructed curves may otherwise be entirely satisfactory. For example, the de Casteljau algorithm may be used to split a curve in affine space; this does not work on a sphere.

The two-valued slerp can be extended to interpolate among many unit quaternions, but the extension loses the fixed execution-time of the slerp algorithm.

See also

References

  1. "Ken Shoemake - Home".
  2. Pennec, Xavier (March 1998). Computing the Mean of Geometric Features Application to the Mean Rotation (report). INRIA. Retrieved 19 June 2020.

External links

Categories: