Sign in to follow this  
ilian

Interpolating between two vectors

Recommended Posts

ilian    138
I was thinking about the problem of interpolating between two orientations which are described as normalized direction vectors (x,y,z). Assuming a Left-Handed coordinate system. Lets say you want to stick with the vectors in this form and do not want to use Euler angles or quats. Thinking along these lines... Two vectors Dir and GoalDir. You can find an axis of rotation by taking a cross product between them. AxisOfRotation = Dir X GoalDir; I know the math to rotate Dir by Theta around this Axis of Rotation. But, which direction do I rotate in? I can find the amount to rotate with the dot product, but its not going to give me the sign of the rotation. I know the cross product should tell me if the rotation is a clockwise or counterclockwise rotation, and If I look at the problem visually (geometrically) I understand how to see it, but im not sure how when looking at the cross product result numerically how to get that info when rotating about an arbitrary axis. Also is this a valid way to do the interpolation between these vectors? What kind of disadvantages does it have when compared to converting the vectors to quats and doing a spherical linear interpolation?

Share this post


Link to post
Share on other sites
jyk    2094
Quote:
Original post by ilian
I was thinking about the problem of interpolating between two orientations which are described as normalized direction vectors (x,y,z). Assuming a Left-Handed coordinate system.

Lets say you want to stick with the vectors in this form and do not want to use Euler angles or quats.

Thinking along these lines...
Two vectors Dir and GoalDir.

You can find an axis of rotation by taking a cross product between them.
AxisOfRotation = Dir X GoalDir;

I know the math to rotate Dir by Theta around this Axis of Rotation.

But, which direction do I rotate in? I can find the amount to rotate with the dot product, but its not going to give me the sign of the rotation.

I know the cross product should tell me if the rotation is a clockwise or counterclockwise rotation, and If I look at the problem visually (geometrically) I understand how to see it, but im not sure how when looking at the cross product result numerically how to get that info when rotating about an arbitrary axis.


Also is this a valid way to do the interpolation between these vectors? What kind of disadvantages does it have when compared to converting the vectors to quats and doing a spherical linear interpolation?
First of all, you can't fully describe an orientation in 3-d using a single direction vector, so we're not really interpolating between two orientations here.

As for the problem of interpolating from one unit-length vector to another, the axis-angle method you mention should work fine (the direction of rotation is 'encoded' in the direction of the cross product, so it's not a problem that the computed angle will always be positive).

Other options for interpolating between two unit-length vectors are SLERP and NLERP.

If I may ask, what are you actually trying to do here?

Share this post


Link to post
Share on other sites
ilian    138
Quote:
Original post by jyk
First of all, you can't fully describe an orientation in 3-d using a single direction vector, so we're not really interpolating between two orientations here.


Yes of course, a bad word choice there, thanks for pointing it out! I apologize for the confusion.


Quote:

(the direction of rotation is 'encoded' in the direction of the cross product, so it's not a problem that the computed angle will always be positive).


Great! This is exactly what I was missing here, for some reason I wasnt putting this part together. Thank you for the clarification.

Quote:

Other options for interpolating between two unit-length vectors are SLERP and NLERP.


Good suggestions! I was just curious about a solution that did not involve quaternions.

Quote:
If I may ask, what are you actually trying to do here?


Just been brushing up on my game math and going over various scenarios and this is one that showed there was a gap in my understanding somewhere.

Share this post


Link to post
Share on other sites
jyk    2094
Quote:
Quote:
Other options for interpolating between two unit-length vectors are SLERP and NLERP.
Good suggestions! I was just curious about a solution that did not involve quaternions.
To clarify, I wasn't actually referring to quaternion SLERP/NLERP, but rather SLERP or NLERP as applied to 3-d vectors.

The SLERP and NLERP algorithms can be applied to vectors of any dimension. What we think of as quaternion SLERP and NLERP are actually just the 4-d versions of these algorithms (more or less - sometimes an extra step is added to work around the fact that q and -q represent the same orientation).

What I was actually suggestion was using the 3-d versions of vector SLERP or NLERP directly to interpolate between the two vectors.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this