/// <summary> /// Clamps a value between two other values. /// </summary> /// <param name="value">Value to clamp.</param> /// <param name="min">Minimum value of the range to clamp. Must be lower than <paramref name="max"/></param> /// <param name="max">Maximum value of the range to clamp. Must be higher than <paramref name="min"/></param> /// <returns>Returns unchanged value if it is in valid range, otherwise returns value clamped to the range /// extremes. </returns> public static Radian Clamp(Radian value, Radian min, Radian max) { if (value < min) { value = min; } else if (value > max) { value = max; } return(value); }
/// <inheritdoc/> public override bool Equals(object other) { if (!(other is Radian)) { return(false); } Radian radian = (Radian)other; if (value.Equals(radian.value)) { return(true); } return(false); }
/// <summary> /// Rotates around local Y axis. /// </summary> /// <param name="angle">Angle to rotate by.</param> public void Yaw(Degree angle) { Radian radianAngle = angle; Internal_Yaw(mCachedPtr, ref radianAngle); }
/// <summary> /// Rotates around local Z axis. /// </summary> /// <param name="angle">Angle to rotate by.</param> public void Roll(Degree angle) { Radian radianAngle = angle; Internal_Roll(mCachedPtr, ref radianAngle); }
/// <summary> /// Returns an angle of a point. /// </summary> /// <param name="y">Y coordinate of the point.</param> /// <param name="x">X coordinate of the point.</param> /// <returns>Angle in radians in range [Pi, -Pi].</returns> public static Radian Atan2(Radian y, Radian x) { return((Radian)Math.Atan2(y.Radians, x.Radians)); }
/// <summary> /// Returns the angle whose tangent is the specified number. /// </summary> /// <param name="f">Tangent of an angle.</param> /// <returns>Angle in radians.</returns> public static Radian Atan(Radian f) { return((Radian)Math.Atan(f.Radians)); }
/// <summary> /// Returns the angle whose cosine is the specified number. /// </summary> /// <param name="f">Cosine of an angle.</param> /// <returns>Angle in radians.</returns> public static Radian Acos(Radian f) { return((Radian)Math.Acos(f.Radians)); }
/// <summary> /// Converts an orthonormal matrix to axis angle representation. /// </summary> /// <param name="axis">Axis around which the rotation is performed.</param> /// <param name="angle">Amount of rotation.</param> public void ToAxisAngle(out Vector3 axis, out Degree angle) { float trace = m00 + m11 + m22; float cos = 0.5f * (trace - 1.0f); Radian radians = (Radian)MathEx.Acos(cos); // In [0, PI] angle = radians; if (radians > (Radian)0.0f) { if (radians < MathEx.Pi) { axis.x = m21 - m12; axis.y = m02 - m20; axis.z = m10 - m01; axis.Normalize(); } else { // Angle is PI float halfInverse; if (m00 >= m11) { // r00 >= r11 if (m00 >= m22) { // r00 is maximum diagonal term axis.x = 0.5f * MathEx.Sqrt(m00 - m11 - m22 + 1.0f); halfInverse = 0.5f / axis.x; axis.y = halfInverse * m01; axis.z = halfInverse * m02; } else { // r22 is maximum diagonal term axis.z = 0.5f * MathEx.Sqrt(m22 - m00 - m11 + 1.0f); halfInverse = 0.5f / axis.z; axis.x = halfInverse * m02; axis.y = halfInverse * m12; } } else { // r11 > r00 if (m11 >= m22) { // r11 is maximum diagonal term axis.y = 0.5f * MathEx.Sqrt(m11 - m00 - m22 + 1.0f); halfInverse = 0.5f / axis.y; axis.x = halfInverse * m01; axis.z = halfInverse * m12; } else { // r22 is maximum diagonal term axis.z = 0.5f * MathEx.Sqrt(m22 - m00 - m11 + 1.0f); halfInverse = 0.5f / axis.z; axis.x = halfInverse * m02; axis.y = halfInverse * m12; } } } } else { // The angle is 0 and the matrix is the identity. Any axis will // work, so just use the x-axis. axis.x = 1.0f; axis.y = 0.0f; axis.z = 0.0f; } }
/// <summary> /// Returns the cosine of the provided value. /// </summary> /// <param name="f">Angle in radians.</param> /// <returns>Cosine of the angle.</returns> public static float Cos(Radian f) { return((float)Math.Cos(f.Radians)); }
private static extern void Internal_setSlopeLimit(IntPtr thisPtr, ref Radian value);
private static extern void Internal_getSlopeLimit(IntPtr thisPtr, out Radian __output);
private static extern void Internal_getHorzFOV(IntPtr thisPtr, out Radian __output);
private static extern void Internal_setHorzFOV(IntPtr thisPtr, ref Radian fovy);
private static extern void Internal_getAngle(IntPtr thisPtr, out Radian __output);
/// <summary> /// Creates a new degree value. /// </summary> /// <param name="r">Value in radians.</param> public Degree(Radian r) { this.value = r.Degrees; }
/// <summary> /// Rotates around local X axis. /// </summary> /// <param name="angle">Angle to rotate by.</param> public void Pitch(Degree angle) { Radian radianAngle = angle; Internal_Pitch(mCachedPtr, ref radianAngle); }
private static extern void Internal_Pitch(IntPtr nativeInstance, ref Radian value);
/// <summary> /// Returns the tangent of the provided value. /// </summary> /// <param name="f">Angle in radians.</param> /// <returns>Tangent of the angle.</returns> public static float Tan(Radian f) { return((float)Math.Tan(f.Radians)); }