Math Type
Contains common mathematical functions. Copied from - https://github.com/opentk/opentk/blob/3.x/src/OpenTK/Math/MathHelper.cs
Static members
Static member | Description |
Full Usage:
Math.ApproximatelyEqual(a, b, tolerance)
Parameters:
float32
-
The first value to compare.
b : float32
-
The second value to compare·
tolerance : float32
-
The tolerance within which the two values would be considered equivalent.
Returns: bool
Whether or not the values can be considered equivalent within the tolerance.
|
Approximates equivalence between two single-precision floating-point numbers on a direct human scale. It is important to note that this does not approximate equality - instead, it merely checks whether or not two numbers could be considered equivalent to each other within a certain tolerance. The tolerance is inclusive.
|
Full Usage:
Math.ApproximatelyEqual(a, b, tolerance)
Parameters:
float
-
The first value to compare.
b : float
-
The second value to compare·
tolerance : float
-
The tolerance within which the two values would be considered equivalent.
Returns: bool
Whether or not the values can be considered equivalent within the tolerance.
|
Approximates equivalence between two double-precision floating-point numbers on a direct human scale. It is important to note that this does not approximate equality - instead, it merely checks whether or not two numbers could be considered equivalent to each other within a certain tolerance. The tolerance is inclusive.
|
Full Usage:
Math.BinomialCoefficient(n, k)
Parameters:
int
-
The n.
k : int
-
The k.
Returns: int64
n! / (k! * (n - k)!)
|
Calculates the binomial coefficient n above k.
|
Full Usage:
Math.Clamp(n, min, max)
Parameters:
int
-
The number to clamp.
min : int
-
The minimum allowed value.
max : int
-
The maximum allowed value.
Returns: int
min, if n is lower than min; max, if n is higher than max; n otherwise.
|
Clamps a number between a minimum and a maximum.
|
Full Usage:
Math.Clamp(n, min, max)
Parameters:
float32
-
The number to clamp.
min : float32
-
The minimum allowed value.
max : float32
-
The maximum allowed value.
Returns: float32
min, if n is lower than min; max, if n is higher than max; n otherwise.
|
Clamps a number between a minimum and a maximum.
|
Full Usage:
Math.Clamp(n, min, max)
Parameters:
float
-
The number to clamp.
min : float
-
The minimum allowed value.
max : float
-
The maximum allowed value.
Returns: float
min, if n is lower than min; max, if n is higher than max; n otherwise.
|
Clamps a number between a minimum and a maximum.
|
|
|
Full Usage:
Math.CopySign(value, sign)
Parameters:
float32
sign : float32
Returns: float
|
Impose the sign of a number onto a value.
|
Full Usage:
Math.CopySign(value, sign)
Parameters:
float
sign : float
Returns: float
|
Impose the sign of a number onto a value.
|
|
|
|
|
Full Usage:
Math.Factorial(n)
Parameters:
int
-
The number.
Returns: int64
n!
|
Calculates the factorial of a given natural number.
|
Full Usage:
Math.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:
Math.Hermite(value1, tangent1, value2, tangent2, amount)
Parameters:
float
-
Source position.
tangent1 : float
-
Source tangent.
value2 : float
-
Source position.
tangent2 : float
-
Source tangent.
amount : float
-
Weighting factor.
Returns: float
The result of the Hermite spline interpolation.
|
Performs a Hermite spline interpolation.
|
|
|
|
|
|
|
Full Usage:
Math.Intersects(plane, frustum, result)
Parameters:
inref<Plane3>
frustum : inref<Frustum>
result : byref<PlaneIntersectionType>
|
|
|
|
|
|
Full Usage:
Math.Intersects(plane, point)
Parameters: Returns: PlaneIntersectionType
The type of intersection of this Plane3 with the specified Vector3.
|
|
|
|
Full Usage:
Math.IsNegative(value)
Parameters:
float32
Returns: bool
|
Determine if a value is negative (includning NaN).
|
Full Usage:
Math.IsNegative(value)
Parameters:
float
Returns: bool
|
Determine if a value is negative (includning NaN).
|
Full Usage:
Math.IsPositive(value)
Parameters:
float32
Returns: bool
|
Determines if value is positive (including NaN).
|
Full Usage:
Math.IsPositive(value)
Parameters:
float
Returns: bool
|
Determines if value is positive (including NaN).
|
Full Usage:
Math.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 Math.LerpPrecise for a less efficient version with more precision around edge cases.
|
Full Usage:
Math.Lerp(value1, value2, amount)
Parameters:
float
-
Source value.
value2 : float
-
Destination value.
amount : float
-
Value between 0 and 1 indicating the weight of value2.
Returns: float
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 Math.LerpPrecise for a less efficient version with more precision around edge cases.
|
Full Usage:
Math.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 Math.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 Math.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), Math.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:
Math.LerpPrecise(value1, value2, amount)
Parameters:
float
-
Source value.
value2 : float
-
Destination value.
amount : float
-
Value between 0 and 1 indicating the weight of value2.
Returns: float
Interpolated value.
|
Linearly interpolates between two values. This method is a less efficient, more precise version of Math.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 Math.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), Math.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:
Math.NextPowerOfTwo(n)
Parameters:
int64
-
The specified number.
Returns: int64
The next power of two.
|
Returns the next power of two that is greater than or equal to the specified number.
|
Full Usage:
Math.NextPowerOfTwo(n)
Parameters:
int
-
The specified number.
Returns: int
The next power of two.
|
Returns the next power of two that is greater than or equal to the specified number.
|
Full Usage:
Math.NextPowerOfTwo(n)
Parameters:
float32
-
The specified number.
Returns: float32
The next power of two.
|
Returns the next power of two that is greater than or equal to the specified number.
|
Full Usage:
Math.NextPowerOfTwo(n)
Parameters:
float
-
The specified number.
Returns: float
The next power of two.
|
Returns the next power of two that is greater than or equal to the specified number.
|
Full Usage:
Math.PowerOfTwo(n)
Parameters:
int64
Returns: bool
|
Determines if a long number is a power of two.
|
Full Usage:
Math.PowerOfTwo(n)
Parameters:
int
Returns: bool
|
Determines if an integer number is a power of two.
|
Full Usage:
Math.PowerOfTwo(n)
Parameters:
float32
Returns: bool
|
Determines if a floating point number is a power of two.
|
Full Usage:
Math.PowerOfTwo(n)
Parameters:
float
Returns: bool
|
Determines if a double precision floating point number is a power of two.
|
|
Convert euler angles in [roll, pitch, yaw] to a quaternion. Sourced from - https://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles
|
|
Convert a quaternion to euler angles in [roll, pitch, yaw]. Sourced from - https://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles NOTE: because this use double-precision calculation, it might be slower than it needs be. TODO: consider using MathF instead once we upgrade to .NET 5.
|
Full Usage:
Math.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:
Math.SmoothStep(value1, value2, amount)
Parameters:
float
-
Source value.
value2 : float
-
Source value.
amount : float
-
Weighting value.
Returns: float
Interpolated value.
|
Interpolates between two values using a cubic equation.
|
Full Usage:
Math.Swap(a, b)
Parameters:
byref<float>
-
The first value.
b : byref<float>
-
The second value.
|
Swaps two double values.
|
Full Usage:
Math.Swap(a, b)
Parameters:
byref<float32>
-
The first value.
b : byref<float32>
-
The second value.
|
Swaps two float values.
|
Full Usage:
Math.ToDegrees(radians)
Parameters:
float32
-
An angle in radians
Returns: float32
The angle expressed in degrees
|
Convert radians to degrees
|
Full Usage:
Math.ToDegrees(radians)
Parameters:
float
-
An angle in radians
Returns: float
The angle expressed in degrees
|
Convert radians to degrees
|
Full Usage:
Math.ToRadians(degrees)
Parameters:
float32
-
An angle in degrees
Returns: float32
The angle expressed in radians
|
Convert degrees to radians
|
Full Usage:
Math.ToRadians(degrees)
Parameters:
float
-
An angle in degrees
Returns: float
The angle expressed in radians
|
Convert degrees to radians
|