MathHelper Type
Contains commonly used precalculated values and mathematical operations. Copied from - https://github.com/MonoGame/MonoGame/blob/develop/MonoGame.Framework/MathHelper.cs
Static members
Static member | Description |
Full Usage:
MathHelper.Barycentric(value1, value2, value3, amount1, amount2)
Parameters:
float32
-
The coordinate on one axis of vertex 1 of the defining triangle.
value2 : float32
-
The coordinate on the same axis of vertex 2 of the defining triangle.
value3 : float32
-
The coordinate on the same axis of vertex 3 of the defining triangle.
amount1 : float32
-
The normalized barycentric (areal) coordinate b2, equal to the weighting factor for vertex 2, the coordinate of which is specified in value2.
amount2 : float32
-
The normalized barycentric (areal) coordinate b3, equal to the weighting factor for vertex 3, the coordinate of which is specified in value3.
Returns: float32
Cartesian coordinate of the specified point with respect to the axis being used.
|
Returns the Cartesian coordinate for one axis of a point that is defined by a given triangle and two normalized barycentric (areal) coordinates.
|
Full Usage:
MathHelper.CatmullRom(value1, value2, value3, value4, amount)
Parameters:
float32
-
The first position in the interpolation.
value2 : float32
-
The second position in the interpolation.
value3 : float32
-
The third position in the interpolation.
value4 : float32
-
The fourth position in the interpolation.
amount : float32
-
Weighting factor.
Returns: float32
A position that is the result of the Catmull-Rom interpolation.
|
Performs a Catmull-Rom interpolation using the specified positions.
|
Full Usage:
MathHelper.Clamp(value, min, max)
Parameters:
float32
-
The value to clamp.
min : float32
-
The minimum value. If value is less than min , min will be returned.
max : float32
-
The maximum value. If value is greater than max , max will be returned.
Returns: float32
The clamped value.
|
Restricts a value to be within a specified range.
|
Full Usage:
MathHelper.Clamp(value, min, max)
Parameters:
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.
Returns: int
The clamped value.
|
Restricts a value to be within a specified range.
|
Full Usage:
MathHelper.Distance(value1, value2)
Parameters:
float32
-
Source value.
value2 : float32
-
Source value.
Returns: float32
Distance between the two values.
|
Calculates the absolute value of the difference of two values.
|
Full Usage:
MathHelper.Hermite(value1, tangent1, value2, tangent2, amount)
Parameters:
float32
-
Source position.
tangent1 : float32
-
Source tangent.
value2 : float32
-
Source position.
tangent2 : float32
-
Source tangent.
amount : float32
-
Weighting factor.
Returns: float32
The result of the Hermite spline interpolation.
|
Performs a Hermite spline interpolation.
|
Full Usage:
MathHelper.IsPowerOfTwo(value)
Parameters:
int
-
A value.
Returns: bool
true if value is powered by two; otherwise false .
|
Determines if value is powered by two.
|
Full Usage:
MathHelper.Lerp(value1, value2, amount)
Parameters:
float32
-
Source value.
value2 : float32
-
Destination value.
amount : float32
-
Value between 0 and 1 indicating the weight of value2.
Returns: float32
Interpolated value.
|
Linearly interpolates between two values. This method performs the linear interpolation based on the following formula:
.
Passing amount a value of 0 will cause value1 to be returned, a value of 1 will cause value2 to be returned.
See MathHelper.LerpPrecise for a less efficient version with more precision around edge cases.
|
Full Usage:
MathHelper.LerpPrecise(value1, value2, amount)
Parameters:
float32
-
Source value.
value2 : float32
-
Destination value.
amount : float32
-
Value between 0 and 1 indicating the weight of value2.
Returns: float32
Interpolated value.
|
Linearly interpolates between two values. This method is a less efficient, more precise version of MathHelper.Lerp. See remarks for more info. This method performs the linear interpolation based on the following formula:
.
Passing amount a value of 0 will cause value1 to be returned, a value of 1 will cause value2 to be returned.
This method does not have the floating point precision issue that MathHelper.Lerp has.
i.e. If there is a big gap between value1 and value2 in magnitude (e.g. value1=10000000000000000, value2=1),
right at the edge of the interpolation range (amount=1), MathHelper.Lerp will return 0 (whereas it should return 1).
This also holds for value1=10^17, value2=10; value1=10^18,value2=10^2... so on.
For an in depth explanation of the issue, see below references:
Relevant Wikipedia Article: https://en.wikipedia.org/wiki/Linear_interpolation#Programming_language_support
Relevant StackOverflow Answer: http://stackoverflow.com/questions/4353525/floating-point-linear-interpolation#answer-23716956
|
Full Usage:
MathHelper.Max(value1, value2)
Parameters:
float32
-
Source value.
value2 : float32
-
Source value.
Returns: float32
The greater value.
|
Returns the greater of two values.
|
Full Usage:
MathHelper.Max(value1, value2)
Parameters:
int
-
Source value.
value2 : int
-
Source value.
Returns: int
The greater value.
|
Returns the greater of two values.
|
Full Usage:
MathHelper.Min(value1, value2)
Parameters:
float32
-
Source value.
value2 : float32
-
Source value.
Returns: float32
The lesser value.
|
Returns the lesser of two values.
|
Full Usage:
MathHelper.Min(value1, value2)
Parameters:
int
-
Source value.
value2 : int
-
Source value.
Returns: int
The lesser value.
|
Returns the lesser of two values.
|
Full Usage:
MathHelper.SmoothStep(value1, value2, amount)
Parameters:
float32
-
Source value.
value2 : float32
-
Source value.
amount : float32
-
Weighting value.
Returns: float32
Interpolated value.
|
Interpolates between two values using a cubic equation.
|
Full Usage:
MathHelper.ToDegrees(radians)
Parameters:
float32
-
The angle in radians.
Returns: float32
The angle in degrees.
|
Converts radians to degrees. This method uses double precision internally, though it returns single float Factor = 180 / pi
|
Full Usage:
MathHelper.ToRadians(degrees)
Parameters:
float32
-
The angle in degrees.
Returns: float32
The angle in radians.
|
Converts degrees to radians. This method uses double precision internally, though it returns single float Factor = pi / 180
|
Full Usage:
MathHelper.WrapAngle(angle)
Parameters:
float32
-
The angle to reduce, in radians.
Returns: float32
The new angle, in radians.
|
Reduces a given angle to a value between π and -π.
|