176 4. 3D Math for Games

`To solve this problem, we can use a variant of the LERP operation known`

as spherical linear interpolation, or SLERP for short. The SLERP operation uses

sines and cosines to interpolate along a great circle of the 4D hypersphere,

rather than along a chord, as shown in Figure 4.23. This results in a constant

angular speed when β varies at a constant rate.

The formula for SLERP is similar to the LERP formula, but the weights

(1 – β) and β are replaced with weights wp and wq involving sines of the angle

between the two quaternions.

`where`

`The cosine of the angle between any two unit-length quaternions can`

be found by taking their four-dimensional dot product. Once we know

cos(θ), we can calculate the angle θ and the various sines we need quite

easily:

`qA (β = 0)`

`qLER P= LERP(qA, qB, 0.4)`

`qB ( β = 1)`

`qSLERP= SLERP (qA, qB, 0.4)`

# (^0). (^4)

alo

ng

cho

rd

(^0). 4

(^) alo

ng

(^) ar

c

Figure 4.23. Spherical linear interpolation along a great circle arc of a 4D hypersphere.

SLERP(p,q, )β=wwpqp+ q,

sin((1 ) )

,

sin( )

sin( ).

sin( )

p

q

w

w

−β θ

θ

= βθ

θ

1

cos( ) p q ;

cos (p q).

pqxx pqyy pqzz p qww

−

θ= =+++

θ=

⋅

⋅