Class MathHelper
Contains commonly used pre-calculated values and mathematical operations.
public static class MathHelper
- Inheritance
-
MathHelper
- Inherited Members
Fields
PiOver2
Represents the value of pi divided by two(1.57079637).
public const float PiOver2 = 1.5707964
Field Value
PiOver4
Represents the value of pi divided by four(0.7853982).
public const float PiOver4 = 0.7853982
Field Value
TwoPi
Represents the value of pi times two(6.28318548).
public const float TwoPi = 6.2831855
Field Value
Methods
Barycentric(float, float, float, float, float)
Returns the Cartesian coordinate for one axis of a point that is defined by a given triangle and two normalized barycentric (areal) coordinates.
public static float Barycentric(float value1, float value2, float value3, float amount1, float amount2)
Parameters
value1floatThe coordinate on one axis of vertex 1 of the defining triangle.
value2floatThe coordinate on the same axis of vertex 2 of the defining triangle.
value3floatThe coordinate on the same axis of vertex 3 of the defining triangle.
amount1floatThe normalized barycentric (areal) coordinate b2, equal to the weighting factor for vertex 2, the coordinate of which is specified in value2.
amount2floatThe normalized barycentric (areal) coordinate b3, equal to the weighting factor for vertex 3, the coordinate of which is specified in value3.
Returns
- float
Cartesian coordinate of the specified point with respect to the axis being used.
CatmullRom(float, float, float, float, float)
Performs a Catmull-Rom interpolation using the specified positions.
public static float CatmullRom(float value1, float value2, float value3, float value4, float amount)
Parameters
value1floatThe first position in the interpolation.
value2floatThe second position in the interpolation.
value3floatThe third position in the interpolation.
value4floatThe fourth position in the interpolation.
amountfloatWeighting factor.
Returns
- float
A position that is the result of the Catmull-Rom interpolation.
CreateQuaternionFromYawPitchRoll(Vector3)
Converts the specified vector containing roll, pitch and yaw in radians to a quaternion.
public static Quaternion CreateQuaternionFromYawPitchRoll(Vector3 rollPitchYaw)
Parameters
rollPitchYawVector3The vector containing roll, pitch and yaw in radians.
Returns
- Quaternion
The quaternion.
CreateYawPitchRollFromQuaternion(Quaternion)
Gets the yaw, pitch and roll in radians from the specified quat.
public static Vector3 CreateYawPitchRollFromQuaternion(Quaternion quat)
Parameters
quatQuaternionThe quaternion
Returns
- Vector3
A vector containing the roll, pitch and yaw components in radians.
Distance(float, float)
Calculates the absolute value of the difference of two values.
public static float Distance(float value1, float value2)
Parameters
Returns
- float
Distance between the two values.
GetZAngleFromRotationMatrix(Matrix4x4)
Gets the Z angle of the specified rotationMatrix.
public static float GetZAngleFromRotationMatrix(Matrix4x4 rotationMatrix)
Parameters
rotationMatrixMatrix4x4The rotation matrix to the Z angle of.
Returns
- float
The Z angle.
Hermite(float, float, float, float, float)
Performs a Hermite spline interpolation.
public static float Hermite(float value1, float tangent1, float value2, float tangent2, float amount)
Parameters
value1floatSource position.
tangent1floatSource tangent.
value2floatSource position.
tangent2floatSource tangent.
amountfloatWeighting factor.
Returns
- float
The result of the Hermite spline interpolation.
IsPowerOfTwo(int)
Determines if value is powered by two.
public static bool IsPowerOfTwo(int value)
Parameters
valueintA value.
Returns
SmoothStep(float, float, float)
Interpolates between two values using a cubic equation.
public static float SmoothStep(float value1, float value2, float amount)
Parameters
Returns
- float
Interpolated value.
WrapAngle(float)
Reduces a given angle to a value between π and -π.
public static float WrapAngle(float angle)
Parameters
anglefloatThe angle to reduce, in radians.
Returns
- float
The new angle, in radians.