Angle distance math function.
@@ -28,7 +28,29 @@ namespace StereoKit
/// <returns>Same as Math.Exp</returns>
public static float Exp(float f) => (float)Math.Exp(f);
+ /// <summary>Blends (Linear Interpolation) between two scalars, based
+ /// on a 'blend' value, where 0 is a, and 1 is b. Doesn't clamp
+ /// percent for you.</summary>
+ /// <param name="a">First item in the blend, or '0.0' blend.</param>
+ /// <param name="b">Second item in the blend, or '1.0' blend.</param>
+ /// <param name="t">A blend value between 0 and 1. Can be outside
+ /// this range, it'll just interpolate outside of the a, b range.
+ /// </param>
+ /// <returns>An unclamped blend of a and b.</returns>
public static float Lerp(float a, float b, float t) => a + (b-a)*t;
+ /// <summary>Calculates the minimum angle 'distance' between two
+ /// angles. This covers wraparound cases like: the minimum distance
+ /// between 10 and 350 is 20. Only works on angles in the range of
+ /// 0-360.</summary>
+ /// <param name="a">First angle, in degrees.</param>
+ /// <param name="b">Second angle, in degrees.</param>
+ /// <returns>Degrees 0-180, the minimum angle between a and b.</returns>
+ public static float AngleDist(float a, float b)
+ {
+ float delta = b-a;
+ if (delta < 0) delta += 360;
+ return delta > 180 ? delta-180 : delta;
+ }
}
}
