# How to interpolate between two vectors...

This topic is 4188 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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 on other sites
Slerp has a geometric form that is independent of quaternions, that you can apply directly to the vectors.

##### Share on other sites
Quote:
 Original post by ZipsterSlerp 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 on other sites
Quote:
Original post by fpsgamer
Quote:
 Original post by ZipsterSlerp 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 on other sites
Quote:
 Original post by ZipsterSlerp 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...

1. 1
2. 2
3. 3
4. 4
Rutin
12
5. 5

• 12
• 16
• 9
• 14
• 10
• ### Forum Statistics

• Total Topics
632658
• Total Posts
3007687
• ### Who's Online (See full list)

There are no registered users currently online

×