Class Slerp

  • All Implemented Interfaces:
    java.util.function.DoubleFunction<Quaternion>

    public class Slerp
    extends java.lang.Object
    implements java.util.function.DoubleFunction<Quaternion>
    Perform spherical linear interpolation (Slerp). The Slerp algorithm is designed to interpolate smoothly between two rotations/orientations, producing a constant-speed motion along an arc. The original purpose of this algorithm was to animate 3D rotations. All output quaternions are in positive polar form, meaning a unit quaternion with a positive scalar component.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private class  Slerp.Linear
      Linear interpolation, used when the quaternions are too closely aligned.
      private class  Slerp.Spherical
      Spherical interpolation, used when the quaternions are too closely aligned.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.function.DoubleFunction<Quaternion> algo
      Linear or spherical interpolation algorithm.
      private Quaternion end
      End of the interpolation.
      private static double MAX_DOT_THRESHOLD
      Threshold max value for the dot product.
      private Quaternion start
      Start of the interpolation.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Quaternion apply​(double t)
      Performs the interpolation.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • MAX_DOT_THRESHOLD

        private static final double MAX_DOT_THRESHOLD
        Threshold max value for the dot product. If the quaternion dot product is greater than this value (i.e. the quaternions are very close to each other), then the quaternions are linearly interpolated instead of spherically interpolated.
        See Also:
        Constant Field Values
      • start

        private final Quaternion start
        Start of the interpolation.
      • end

        private final Quaternion end
        End of the interpolation.
      • algo

        private final java.util.function.DoubleFunction<Quaternion> algo
        Linear or spherical interpolation algorithm.
    • Constructor Detail

      • Slerp

        public Slerp​(Quaternion start,
                     Quaternion end)
        Parameters:
        start - Start of the interpolation.
        end - End of the interpolation.
    • Method Detail

      • apply

        public Quaternion apply​(double t)
        Performs the interpolation. The rotation returned by this method is controlled by the interpolation parameter, t. All other values are interpolated (or extrapolated if t is outside of the [0, 1] range). The returned quaternion is in positive polar form, meaning that it is a unit quaternion with a positive scalar component.
        Specified by:
        apply in interface java.util.function.DoubleFunction<Quaternion>
        Parameters:
        t - Interpolation control parameter. When t = 0, a rotation equal to the start instance is returned. When t = 1, a rotation equal to the end instance is returned.
        Returns:
        an interpolated quaternion in positive polar form.