# Divide two quaternions evenly by a scalar to get a smooth rotation in-between

How do you divide two quaternions - say A and B - evenly by a scalar, to calculate the rotations between them to render a smoother rotation?

Effectively, say you want to smooth the rotations between A and B evenly by n. How do you calculate each quaternion value between A and B?

I have found that resorting to .eulerAngles leads to some wild gimbal locking, so I think the math needs to stay in quaternion space...

## 1 Answer

It sounds like you're describing Quaternion.Slerp. You can use this to generate quaternion at any particular fraction of the rotation between a start and an end quaternion:

IEnumerator<Quaternion> RotationSteps(Quaternion from, Quaternion to, int stepCount) {

yield return from;

for(int i = 1; i < stepCount; i++) {
yield return Quaternion.Slerp(
from,
to,
i / (float)stepCount
);
}

yield return to;
}


Or you can compute the incremental rotation of a single step like so:

Quaternion travel = to * Quaternion.Inverse(from);

Quaternion step = Quaternion.Slerp(
Quaternion.identity,
travel,
1f / stepCount
);