- Home /
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.
Answer by cregox · Feb 23, 2011 at 06:34 PM
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.
Unfortunately, this doesn't account for spin around the vector you're tracking. It may work if that's not an issue, though. I use FromToRotation for 2D rotations, because I don't know any better yet. :-D
@Jessy yes, that's true... This will rotate in just one 2D plane. I think I wrongly assumed "constant velocity" as being 2D. It's hard to get my head around this subject sometimes! :)
Your answer
Follow this Question
Related Questions
Rotation of an object with quaternion 1 Answer
Choppy rotation of character around y-axis 1 Answer
i want to get my to cube to rotate 90 degrees on the x-axis as it jumps 0 Answers
Stage selection problem 1 Answer
Changing rotation of Quaternion 0 Answers