Sign in to follow this  
fpsgamer

How to interpolate between two vectors...

Recommended Posts

I have two vectors I want to interpolate between (interpolate their directions). My initial inclination was to use quaternions which can be interpolated with a slerp. The problem is that I know how to convert euler angles to a quaternion, but I am not so sure on how to represent a 3D vector by euler angles. Could someone please explain to me how to do this ... or perhaps offer a different method for interpolating between two vectors.

Share this post


Link to post
Share on other sites
I'm not an expert on this subject, but I think you could convert an axis/zngle representation of an orientation to a quaternion using something like here. You apparently only have an axis, so you could probably default the angle around the axis to 0, which apparently simplifies down to making the quaternion a copy of the vector, with the fourth component set to 1.

After a slerp, you can just do the inverse to get back an axis and angle combination, if you need that.

Share this post


Link to post
Share on other sites
Quote:
Original post by Zipster
Slerp has a geometric form that is independent of quaternions, that you can apply directly to the vectors.


So all I do is write the vector as [x y z] and apply the slerp and it will just work?

Share this post


Link to post
Share on other sites
Quote:
Original post by fpsgamer
Quote:
Original post by Zipster
Slerp has a geometric form that is independent of quaternions, that you can apply directly to the vectors.


So all I do is write the vector as [x y z] and apply the slerp and it will just work?

Indeed. There's a small caveat, if sin(Ω) is 0 or very close to it, you might end up with a divide-by-zero, so you want to check for that first. If Ω = 0 then you're lucky and can just do nothing, but if Ω = PI then you have to disambiguate the interpolation "direction" somehow if you want anything to happen.

Share this post


Link to post
Share on other sites
Quote:
Original post by Zipster
Slerp has a geometric form that is independent of quaternions, that you can apply directly to the vectors.


Interesting, never saw that... the alternative is to take the cross product of the two vectors to determine the axis and angle. Convert the axis/angle representation to a matrix representation parameterized by angle... and multiply your starting vector by the matrix as you vary the angle. Should be equivalent to the slerp, but probably take some tedious math to show that...

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