Same as System.Math.Acos but if angle is out of range, the result is clamped.

image_pdfimage_print
   
 
public static class MathUtility
{
    //-------------------------------------------------------------------------------------
    /// <summary>
    /// Same as System.Math.Acos but if angle is out of range, the result is clamped.
    /// </summary>
    /// <param name="angle">Input angle.</param>
    /// <returns>Acos the angle.</returns>
    //-------------------------------------------------------------------------------------

    public static float SafeAcos(float angle)
        {
            if(angle <= -1.0f)
            {
                return (float) (System.Math.PI);
            }

            if(angle >= 1.0f)
            {
                return 0.0f;
            }

            return (float) System.Math.Acos(angle);
        }
}