Java Lerp lerpa(double a1, double a2, double t)

Here you can find the source of lerpa(double a1, double a2, double t)

Description

Linearly interpolates between two angles, taking the shortest path around the circle.

License

Apache License

Declaration

public static double lerpa(double a1, double a2, double t) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**//from   ww  w .  java2 s.co  m
     * Linearly interpolates between two angles, taking the shortest path around the circle.
     * This assumes that both angles are in [-pi, +pi].
     */
    public static double lerpa(double a1, double a2, double t) {
        double ma1 = mirrorAngle(a1), ma2 = mirrorAngle(a2);
        double d = Math.abs(a2 - a1), md = Math.abs(ma1 - ma2);
        return (d <= md) ? lerp(a1, a2, t) : mirrorAngle(lerp(ma1, ma2, t));
    }

    /**
     * Returns the mirror angle of the specified angle (assumed to be in [-pi, +pi]). The angle is
     * mirrored around the PI/2 if it is positive, and -PI/2 if it is negative. One can visualize
     * this as mirroring around the "y-axis".
     */
    public static double mirrorAngle(double a) {
        return (a > 0f ? Math.PI : -Math.PI) - a;
    }

    /**
     * Linearly interpolates between v1 and v2 by the parameter t.
     */
    public static double lerp(double v1, double v2, double t) {
        return v1 + t * (v2 - v1);
    }
}

Related

  1. lerp(float to, float from, float f)
  2. lerp(float va, float vb, float t)
  3. lerp(float value1, float value2, float amount)
  4. lerp(int a, int b, float value)
  5. lerp(int a, int b, int mul, int div)
  6. lerpAndPremultiplyColorWithAlpha(float t, int[] color1, int[] color2)
  7. lerpAngle(float fromRadians, float toRadians, float progress)
  8. LerpDegrees(float start, float end, float amount)
  9. lerpInt(int i1, int i2, double f)