C# Class Server.Utils.Math.MathHelper

Contains commonly used precalculated values and mathematical operations.
Mostra file Open project: GrindFest/GrindFest

Public Methods

Method Description
Barycentric ( float value1, float value2, float value3, float amount1, float amount2 ) : float

Returns the Cartesian coordinate for one axis of a point that is defined by a given triangle and two normalized barycentric (areal) coordinates.

CatmullRom ( float value1, float value2, float value3, float value4, float amount ) : float

Performs a Catmull-Rom interpolation using the specified positions.

Clamp ( float value, float min, float max ) : float

Restricts a value to be within a specified range.

Clamp ( int value, int min, int max ) : int

Restricts a value to be within a specified range.

Distance ( float value1, float value2 ) : float

Calculates the absolute value of the difference of two values.

Hermite ( float value1, float tangent1, float value2, float tangent2, float amount ) : float

Performs a Hermite spline interpolation.

IsPowerOfTwo ( int value ) : bool

Determines if value is powered by two.

Lerp ( float value1, float value2, float amount ) : float

Linearly interpolates between two values.

This method performs the linear interpolation based on the following formula. value1 + (value2 - value1) * amount Passing amount a value of 0 will cause value1 to be returned, a value of 1 will cause value2 to be returned.

Max ( float value1, float value2 ) : float

Returns the greater of two values.

Min ( float value1, float value2 ) : float

Returns the lesser of two values.

SmoothStep ( float value1, float value2, float amount ) : float

Interpolates between two values using a cubic equation.

ToDegrees ( float radians ) : float

Converts radians to degrees.

This method uses double precission internally, though it returns single float Factor = 180 / pi

ToRadians ( float degrees ) : float

Converts degrees to radians.

This method uses double precission internally, though it returns single float Factor = pi / 180

WrapAngle ( float angle ) : float

Reduces a given angle to a value between π and -π.

Method Details

Barycentric() public static method

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 Barycentric ( float value1, float value2, float value3, float amount1, float amount2 ) : float
value1 float The coordinate on one axis of vertex 1 of the defining triangle.
value2 float The coordinate on the same axis of vertex 2 of the defining triangle.
value3 float The coordinate on the same axis of vertex 3 of the defining triangle.
amount1 float The normalized barycentric (areal) coordinate b2, equal to the weighting factor for vertex 2, the coordinate of which is specified in value2.
amount2 float The normalized barycentric (areal) coordinate b3, equal to the weighting factor for vertex 3, the coordinate of which is specified in value3.
return float

CatmullRom() public static method

Performs a Catmull-Rom interpolation using the specified positions.
public static CatmullRom ( float value1, float value2, float value3, float value4, float amount ) : float
value1 float The first position in the interpolation.
value2 float The second position in the interpolation.
value3 float The third position in the interpolation.
value4 float The fourth position in the interpolation.
amount float Weighting factor.
return float

Clamp() public static method

Restricts a value to be within a specified range.
public static Clamp ( float value, float min, float max ) : float
value float The value to clamp.
min float The minimum value. If value is less than min, min will be returned.
max float The maximum value. If value is greater than max, max will be returned.
return float

Clamp() public static method

Restricts a value to be within a specified range.
public static Clamp ( int value, int min, int max ) : int
value int The value to clamp.
min int The minimum value. If value is less than min, min will be returned.
max int The maximum value. If value is greater than max, max will be returned.
return int

Distance() public static method

Calculates the absolute value of the difference of two values.
public static Distance ( float value1, float value2 ) : float
value1 float Source value.
value2 float Source value.
return float

Hermite() public static method

Performs a Hermite spline interpolation.
public static Hermite ( float value1, float tangent1, float value2, float tangent2, float amount ) : float
value1 float Source position.
tangent1 float Source tangent.
value2 float Source position.
tangent2 float Source tangent.
amount float Weighting factor.
return float

IsPowerOfTwo() public static method

Determines if value is powered by two.
public static IsPowerOfTwo ( int value ) : bool
value int A value.
return bool

Lerp() public static method

Linearly interpolates between two values.
This method performs the linear interpolation based on the following formula. value1 + (value2 - value1) * amount Passing amount a value of 0 will cause value1 to be returned, a value of 1 will cause value2 to be returned.
public static Lerp ( float value1, float value2, float amount ) : float
value1 float Source value.
value2 float Source value.
amount float Value between 0 and 1 indicating the weight of value2.
return float

Max() public static method

Returns the greater of two values.
public static Max ( float value1, float value2 ) : float
value1 float Source value.
value2 float Source value.
return float

Min() public static method

Returns the lesser of two values.
public static Min ( float value1, float value2 ) : float
value1 float Source value.
value2 float Source value.
return float

SmoothStep() public static method

Interpolates between two values using a cubic equation.
public static SmoothStep ( float value1, float value2, float amount ) : float
value1 float Source value.
value2 float Source value.
amount float Weighting value.
return float

ToDegrees() public static method

Converts radians to degrees.
This method uses double precission internally, though it returns single float Factor = 180 / pi
public static ToDegrees ( float radians ) : float
radians float The angle in radians.
return float

ToRadians() public static method

Converts degrees to radians.
This method uses double precission internally, though it returns single float Factor = pi / 180
public static ToRadians ( float degrees ) : float
degrees float The angle in degrees.
return float

WrapAngle() public static method

Reduces a given angle to a value between π and -π.
public static WrapAngle ( float angle ) : float
angle float The angle to reduce, in radians.
return float