Jump to content


- - - - -

Lin. interpolation of unit vectors = unit vector?


3 replies to this topic

#1 Mihail121

    Senior Member

  • Members
  • PipPipPipPip
  • 1059 posts

Posted 02 October 2009 - 06:03 PM

The question pretty much sums it up, is it true that:

| A + t * ((B-A)/l) | = 1

for l > 0 and 0 <= t <= l. I can work out the maths, but I got some weird results, so I think I have an error somewhere along the lines. I've googled, of course, and found a book saying one should renormalize, but does not state why. If the above does not hold indeed, I would ask you to provide some hints as to what kind of interpolation, if any, will yield this result.

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 5308 posts
  • LocationSanta Clara, CA

Posted 02 October 2009 - 06:12 PM

No. When you lerp, the interpolated point lies on a straight line between the two endpoints. If the endpoints are on the surface of the unit sphere, the interpolation will trace out a chord of the sphere, not an arc.

You can renormalize after lerping, and this is good enough for many cases (e.g. shaders). It doesn't however give you a linear relationship between the interpolation parameter (t) and the change in angle (or equivalently, arc length on the sphere) - the nonlinearity being greater the wider is the angle between the endpoints. You can counteract this by using slerping at the cost of some additional math.

Either method (renormalize or slerp) also blows up if you try to interpolate between antipodal points, such as (1, 0, 0) and (-1, 0, 0), as there are then an infinity of possible shortest paths. If you need to handle such points you can special-case it and choose one of the paths arbitrarily.
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 Mihail121

    Senior Member

  • Members
  • PipPipPipPip
  • 1059 posts

Posted 02 October 2009 - 06:24 PM

Reedbeta said:

No. When you lerp, the interpolated point lies on a straight line between the two endpoints. If the endpoints are on the surface of the unit sphere, the interpolation will trace out a chord of the sphere, not an arc.

OMFG, THANK YOU REED. I went into outburstive maths right away and totally forgot to look for the trivial geometrical interpretation, thanks!

#4 .oisyn

    DevMaster Staff

  • Moderators
  • 1842 posts

Posted 02 October 2009 - 07:58 PM

If you want a spherical interpolation, take the cross product of the two vectors. The length of that vector is the sine of the angle between the two vectors, and the normalized vector will be the axis of rotation. You can use that to build a rotation matrix about the axis with a lerped angle.

You could also just lerp the vectors and normalize. That will yield the same arc, but not with a constant speed (the point on the arc will move fastest at t=0.5, when the lerped vector is the shortest)
C++ addict
-
Currently working on: the 3D engine for Tomb Raider.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users