When searching for slerp, I get this text:

Slerp is shorthand for spherical linear interpolation, introduced by Ken Shoemake in the context of quaternion interpolation for the purpose of animating 3D rotation.

As far as I understand it, slerp is important for rotations in 3D, since the rotation is composed of multiple angles and it's important to consider the whole structure rather than each number individually.

However, I've also heard of people choosing between lerp and slerp for a single angle for rotation in 2D (where lerp is done with a lerp_angle method takes into account rotations in both directions). I don't understand what slerp would mean in 2D or how it would be different. Is there some case in which lerp doesn't work right in 2D? Is the behavior different, how?


What happens if you do a linear interpolation of 0.5 between the angles 359° and 1°? you get 180°. But what you really wanted is 0°, since it lies on the shortest path between both angles. So you get some kind of "wrapping problem". It is nothing you can't fix with some branches, but it gets messy. Since you don't want to repeat all those special case treatments, every time you interpolate 2 angles, you will probably write a function that handles this. How would you call this one? Maybe SLERP ;) SLERP is just a term and not strictly bound to quaternions. Wikipedia says:

It refers to constant-speed motion along a unit-radius great circle arc, given the ends and an interpolation parameter between 0 and 1.

So a LERP with angles and some special case correction will also behave like this. I don't know for sure if you can really call this SLERP or if the term has some more constraints on the algorithm, but "from the outside" they behave the same.

If you don't like those branches and you think quaternions are too much dead weight in 2D, there is an article I found addressing this problem: click me

In case the link expires and for future reference: The article talks about using "spinors" in 2D similar to quaternions in 3d.

  • 1
    \$\begingroup\$ I think it's worth emphasizing the constant speed part. Linearly interpolating a rotation matrix or complex number "spinor" will produce intermediates that aren't evenly-distributed as you vary the blend parameter. The blend will go fastest in the middle, and slower at the start/end, assuming you're correcting for scale so you don't distort the object along the way. With SLERP, the blend is guaranteed to be uniform. But there are many cases where we don't need that uniformity, and a quick LERP with corrections is enough. \$\endgroup\$ – DMGregory Apr 28 '20 at 7:49
  • \$\begingroup\$ @DMGregory This is generally correct, but in this case, the question was about LERPing angles. So if you create a rotation matrix out of the interpolated angles you should also get evenly distributed rotations. \$\endgroup\$ – wychmaster Apr 28 '20 at 8:21
  • \$\begingroup\$ As I mentioned in the OP, lerping of angles is done with a lerp_angle function that handles wrapping: github.com/godotengine/godot/blob/master/core/math/… \$\endgroup\$ – Aaron Franke Apr 29 '20 at 17:49
  • \$\begingroup\$ Wasn't sure what you meant with "takes into account rotations in both directions". So I went the safe route mentioning the wrapping problem. ;) As I said in the answer, they don't differ from the outside and I am not sure if you can't call the angle method also SLERP. Apart from that, there might be slight performance differences. Quaternions in 2d are a lot of redundant work. If spinors really behave like quaternions in 2d, they have the benefit of being branchless, but without benchmarking your special use case, it is hard to tell what is better. \$\endgroup\$ – wychmaster Apr 29 '20 at 18:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.