add angle bounding functions

This commit is contained in:
BobLd
2020-05-23 19:03:38 +01:00
committed by Eliot Jones
parent 404d6621de
commit d2c2a2f592

View File

@@ -78,6 +78,28 @@
return Math.Abs(point2.X - point1.X);
}
/// <summary>
/// Bound angle so that -180 ≤ θ ≤ 180.
/// </summary>
/// <param name="angle">The angle to bound.</param>
public static double BoundAngle180(double angle)
{
angle = (angle + 180) % 360;
if (angle < 0) angle += 360;
return angle - 180;
}
/// <summary>
/// Bound angle so that 0 ≤ θ ≤ 360.
/// </summary>
/// <param name="angle">The angle to bound.</param>
public static double BoundAngle0to360(double angle)
{
angle %= 360;
if (angle < 0) angle += 360;
return angle;
}
/// <summary>
/// Get the minimum edit distance between two strings.
/// </summary>