Overview

  • SLERP moves between two orientations along the shortest arc on the unit quaternion sphere, at a constant angular speed
  • it is driven by a path parameter , which usually comes from an S-curve or quintic time law
  • two practical rules: flip the sign of when , and switch to NLERP when the angle is tiny

Linear interpolation of rotation matrices or Euler angles does not stay on the rotation group: a straight line between two rotation matrices is not a rotation matrix, and Euler angles can pass through gimbal lock. SLERP stays on the unit quaternion sphere , so every in between value is a valid rotation.


Mathematical Formulation

Angle between two quaternions

Treat as 4D unit vectors:

is a half angle: the physical rotation from to is .

Shortest path

and are the same rotation (double cover). If , the arc to is the long way round, so use :

SLERP formula

Equivalent forms:

In rotation matrix form:

Angular velocity

The relative rotation has a fixed unit axis and angle . Along SLERP only the angle grows, so:

The axis is fixed, so the speed profile is set only by . A quintic gives smooth angular acceleration, while a constant gives a constant angular speed.

Small angle fallback (NLERP)

When , and the formula divides by almost zero. Below a threshold (for example ) use normalised linear interpolation:

The path is the same, but the speed is slightly non uniform, which does not matter at small angles.

Several waypoints

Chaining SLERP segments keeps the orientation continuous, but jumps at each waypoint because the axis changes. For a smooth path through many orientations, use SQUAD or a spline in the tangent space ( of the relative rotations).

Input and output layout

FieldSymbolDim
start orientation4
goal orientation4
path parameter and rate2
output orientation4
output angular velocity3

Algorithmic / Architectural Flow

flowchart LR
    A["q0, q1 normalised"] --> B["d = q0 dot q1"]
    B --> C{"d below 0?"}
    C -- yes --> D["q1 = -q1, d = -d"]
    C -- no --> E{"d above 0.9995?"}
    D --> E
    E -- yes --> F["NLERP"]
    E -- no --> G["SLERP with Omega = acos d"]
    F --> H["Normalise output"]
    G --> H
import numpy as np
 
def slerp(q0, q1, sigma, eps=0.9995):   # q as (w, x, y, z)
    q0 = q0 / np.linalg.norm(q0)
    q1 = q1 / np.linalg.norm(q1)
    d = np.dot(q0, q1)
    if d < 0.0:                           # shortest path
        q1, d = -q1, -d
    if d > eps:                           # tiny angle: NLERP
        q = (1 - sigma) * q0 + sigma * q1
        return q / np.linalg.norm(q)
    omega = np.arccos(np.clip(d, -1.0, 1.0))
    s = np.sin(omega)
    q = (np.sin((1 - sigma) * omega) * q0 + np.sin(sigma * omega) * q1) / s
    return q / np.linalg.norm(q)

Sim-to-Real & Hardware Failure Modes

Things that break on hardware:

  • component order: ROS messages use while many maths libraries use , mixing them gives a valid looking but wrong rotation
  • missing sign flip: the wrist turns instead of , which can wrap cables or hit a joint limit
  • targets near 180 degrees: at (a half turn) the shortest direction is ambiguous, so sensor noise can flip it between ticks and the wrist chatters when the target is re planned every tick, add hysteresis on the sign choice
  • non unit inputs: quaternions from an estimator or IMU drift off unit length, normalise before and after
  • geodesic in SO(3), not in joint space: the shortest orientation path can still pass a wrist singularity, so IK needs a singularity check on the path
  • wrong frame: interpolating in the base frame of a moving base gives a different world motion than interpolating in the world frame