# Extrapolating a new rotation from two existing rotations.

I have two rotations of an object that are a given time apart. From these I would like to extrapolate the rotation in the next frame assuming the object has a constant rotational velocity. Slerp() will interpolate between two rotations but my understanding is that the "t" argument must be between 0 and 1. I'm looking for the equivalent of Slerp() that accepts "t" values greater than one.

Perhaps quaternion operations can be used to find the difference between the first and second rotations and then this difference can be applied to the second rotation yielding the next rotation in the sequence. My understanding of quaternions is still rather slim. I appreciate any suggestions that you might have.

Assuming the rotational velocity is constant, like you said, we just need the difference between the first two to add up and get the third rotation. Don't need to understand quaternions rotations for doing that. Just do all math in Euler angles and rotate using Quaternion.FromToRotation:

``````function extrapolateLinearRotation (var dir1, var dir2) {
var dir3 = dir1 - dir2;
dir3 = dir2 + dir3;
return Quaternion.FromToRotation(dir2, dir3);
}

``````

edit: This will only account for 1 plane rotation, and will not get the vector spin as Jessy pointed on the comments. My actual point here was that it's important to do the actual rotation with quaternions to avoid a Gimbal Lock.

Picture this on a dice, if you will. This will be confusing.

Number 1 on the top, number 2 on the front, number 3 on the right. Now rotate the dice upwards so number 1 gets on the back, 2 on the top and 6 on the front. 3 stays on the right. This code will notice that change and next step number 1 is on the bottom. But it won't account for any changes on number 3. If from step 1 to step 2 we have moved number 3 to the left, on step 3 number 3 should be moved back to the right to continue its spin. That just doesn't happen with FromToRotation.