Header menu logo Nu

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

Math.ApproximatelyEqual(a, b, tolerance)

Full Usage: Math.ApproximatelyEqual(a, b, tolerance)

Parameters:
    a : 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.

a : 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.

Math.ApproximatelyEqual(a, b, tolerance)

Full Usage: Math.ApproximatelyEqual(a, b, tolerance)

Parameters:
    a : 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.

a : 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.

Math.BinomialCoefficient(n, k)

Full Usage: Math.BinomialCoefficient(n, k)

Parameters:
    n : int - The n.
    k : int - The k.

Returns: int64 n! / (k! * (n - k)!)

Calculates the binomial coefficient n above k.

n : int

The n.

k : int

The k.

Returns: int64

n! / (k! * (n - k)!)

Math.Clamp(n, min, max)

Full Usage: Math.Clamp(n, min, max)

Parameters:
    n : 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.

n : 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.

Math.Clamp(n, min, max)

Full Usage: Math.Clamp(n, min, max)

Parameters:
    n : 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.

n : 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.

Math.Clamp(n, min, max)

Full Usage: Math.Clamp(n, min, max)

Parameters:
    n : 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.

n : 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.

Math.ClassifyPoint(plane, point)

Full Usage: Math.ClassifyPoint(plane, point)

Parameters:
    plane : inref<Plane3> - The plane to check against
    point : inref<Vector3> - The point to check with

Returns: float32 Greater than zero if on the positive side, less than zero if on the negative size, 0 otherwise

Returns a value indicating what side (positive/negative) of a plane a point is

plane : inref<Plane3>

The plane to check against

point : inref<Vector3>

The point to check with

Returns: float32

Greater than zero if on the positive side, less than zero if on the negative size, 0 otherwise

Math.CopySign(value, sign)

Full Usage: Math.CopySign(value, sign)

Parameters:
    value : float32
    sign : float32

Returns: float

Impose the sign of a number onto a value.

value : float32
sign : float32
Returns: float

Math.CopySign(value, sign)

Full Usage: Math.CopySign(value, sign)

Parameters:
    value : float
    sign : float

Returns: float

Impose the sign of a number onto a value.

value : float
sign : float
Returns: float

Math.DotCoordinate(plane, value)

Full Usage: Math.DotCoordinate(plane, value)

Parameters:
Returns: float32 The dot product of the specified Vector3 and the normal of this Plane3 plus the !:D value of this Plane3.

Get the dot product of a Vector3 with the !:Normal vector of this Plane3 plus the !:D value of this Plane3.

plane : Plane3
value : Vector3

The Vector3 to calculate the dot product with.

Returns: float32

The dot product of the specified Vector3 and the normal of this Plane3 plus the !:D value of this Plane3.

Math.DotCoordinate(plane, value, result)

Full Usage: Math.DotCoordinate(plane, value, result)

Parameters:
    plane : inref<Plane3>
    value : inref<Vector3> - The Vector3 to calculate the dot product with.
    result : byref<float32> - The dot product of the specified Vector3 and the normal of this Plane3 plus the !:D value of this Plane3.

Get the dot product of a Vector3 with the !:Normal vector of this Plane3 plus the !:D value of this Plane3.

plane : inref<Plane3>
value : inref<Vector3>

The Vector3 to calculate the dot product with.

result : byref<float32>

The dot product of the specified Vector3 and the normal of this Plane3 plus the !:D value of this Plane3.

Math.Factorial(n)

Full Usage: Math.Factorial(n)

Parameters:
    n : int - The number.

Returns: int64 n!

Calculates the factorial of a given natural number.

n : int

The number.

Returns: int64

n!

Math.Hermite(value1, tangent1, value2, tangent2, amount)

Full Usage: Math.Hermite(value1, tangent1, value2, tangent2, amount)

Parameters:
    value1 : 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.

value1 : 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.

Math.Hermite(value1, tangent1, value2, tangent2, amount)

Full Usage: Math.Hermite(value1, tangent1, value2, tangent2, amount)

Parameters:
    value1 : 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.

value1 : 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.

Math.Intersects(plane, box)

Full Usage: Math.Intersects(plane, box)

Parameters:
    plane : inref<Plane3>
    box : Box3 - The Box3 to test for intersection.

Returns: PlaneIntersectionType The type of intersection of this Plane3 with the specified Box3.

Check if this Plane3 intersects a Box3.

plane : inref<Plane3>
box : Box3

The Box3 to test for intersection.

Returns: PlaneIntersectionType

The type of intersection of this Plane3 with the specified Box3.

Math.Intersects(plane, box, result)

Full Usage: Math.Intersects(plane, box, result)

Parameters:

Check if this Plane3 intersects a Box3.

plane : inref<Plane3>
box : byref<Box3>

The Box3 to test for intersection.

result : byref<PlaneIntersectionType>

The type of intersection of this Plane3 with the specified Box3.

Math.Intersects(plane, frustum)

Full Usage: Math.Intersects(plane, frustum)

Parameters:
Returns: PlaneIntersectionType The type of intersection of this Plane3 with the specified Frustum.

Check if this Plane3 intersects a Frustum.

plane : inref<Plane3>
frustum : Frustum

The Frustum to test for intersection.

Returns: PlaneIntersectionType

The type of intersection of this Plane3 with the specified Frustum.

Math.Intersects(plane, frustum, result)

Full Usage: Math.Intersects(plane, frustum, result)

Parameters:
plane : inref<Plane3>
frustum : inref<Frustum>
result : byref<PlaneIntersectionType>

Math.Intersects(plane, sphere)

Full Usage: Math.Intersects(plane, sphere)

Parameters:
Returns: PlaneIntersectionType The type of intersection of this Plane3 with the specified Sphere.

Check if this Plane3 intersects a Sphere.

plane : inref<Plane3>
sphere : Sphere

The Sphere to test for intersection.

Returns: PlaneIntersectionType

The type of intersection of this Plane3 with the specified Sphere.

Math.Intersects(plane, sphere, result)

Full Usage: Math.Intersects(plane, sphere, result)

Parameters:

Check if this Plane3 intersects a Sphere.

plane : inref<Plane3>
sphere : inref<Sphere>

The Sphere to test for intersection.

result : byref<PlaneIntersectionType>

The type of intersection of this Plane3 with the specified Sphere.

Math.Intersects(plane, point)

Full Usage: Math.Intersects(plane, point)

Parameters:
Returns: PlaneIntersectionType The type of intersection of this Plane3 with the specified Vector3.

Check if this Plane3 intersects a Vector3.

plane : inref<Plane3>
point : Vector3
Returns: PlaneIntersectionType

The type of intersection of this Plane3 with the specified Vector3.

Math.Intersects(plane, point, result)

Full Usage: Math.Intersects(plane, point, result)

Parameters:

Check if this Plane3 intersects a Vector3.

plane : inref<Plane3>
point : inref<Vector3>

The Vector3 to test for intersection.

result : byref<PlaneIntersectionType>

The type of intersection of this Plane3 with the specified Vector3.

Math.IsNegative(value)

Full Usage: Math.IsNegative(value)

Parameters:
    value : float32

Returns: bool

Determine if a value is negative (includning NaN).

value : float32
Returns: bool

Math.IsNegative(value)

Full Usage: Math.IsNegative(value)

Parameters:
    value : float

Returns: bool

Determine if a value is negative (includning NaN).

value : float
Returns: bool

Math.IsPositive(value)

Full Usage: Math.IsPositive(value)

Parameters:
    value : float32

Returns: bool

Determines if value is positive (including NaN).

value : float32
Returns: bool

Math.IsPositive(value)

Full Usage: Math.IsPositive(value)

Parameters:
    value : float

Returns: bool

Determines if value is positive (including NaN).

value : float
Returns: bool

Math.Lerp(value1, value2, amount)

Full Usage: Math.Lerp(value1, value2, amount)

Parameters:
    value1 : 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:

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. See Math.LerpPrecise for a less efficient version with more precision around edge cases.

value1 : float32

Source value.

value2 : float32

Destination value.

amount : float32

Value between 0 and 1 indicating the weight of value2.

Returns: float32

Interpolated value.

Math.Lerp(value1, value2, amount)

Full Usage: Math.Lerp(value1, value2, amount)

Parameters:
    value1 : 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:

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. See Math.LerpPrecise for a less efficient version with more precision around edge cases.

value1 : float

Source value.

value2 : float

Destination value.

amount : float

Value between 0 and 1 indicating the weight of value2.

Returns: float

Interpolated value.

Math.LerpPrecise(value1, value2, amount)

Full Usage: Math.LerpPrecise(value1, value2, amount)

Parameters:
    value1 : 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:

((1 - amount) * value1) + (value2 * amount)
. 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

value1 : float32

Source value.

value2 : float32

Destination value.

amount : float32

Value between 0 and 1 indicating the weight of value2.

Returns: float32

Interpolated value.

Math.LerpPrecise(value1, value2, amount)

Full Usage: Math.LerpPrecise(value1, value2, amount)

Parameters:
    value1 : 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:

((1 - amount) * value1) + (value2 * amount)
. 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

value1 : float

Source value.

value2 : float

Destination value.

amount : float

Value between 0 and 1 indicating the weight of value2.

Returns: float

Interpolated value.

Math.NextPowerOfTwo(n)

Full Usage: Math.NextPowerOfTwo(n)

Parameters:
    n : 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.

n : int64

The specified number.

Returns: int64

The next power of two.

Math.NextPowerOfTwo(n)

Full Usage: Math.NextPowerOfTwo(n)

Parameters:
    n : 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.

n : int

The specified number.

Returns: int

The next power of two.

Math.NextPowerOfTwo(n)

Full Usage: Math.NextPowerOfTwo(n)

Parameters:
    n : 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.

n : float32

The specified number.

Returns: float32

The next power of two.

Math.NextPowerOfTwo(n)

Full Usage: Math.NextPowerOfTwo(n)

Parameters:
    n : 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.

n : float

The specified number.

Returns: float

The next power of two.

Math.PowerOfTwo(n)

Full Usage: Math.PowerOfTwo(n)

Parameters:
    n : int64

Returns: bool

Determines if a long number is a power of two.

n : int64
Returns: bool

Math.PowerOfTwo(n)

Full Usage: Math.PowerOfTwo(n)

Parameters:
    n : int

Returns: bool

Determines if an integer number is a power of two.

n : int
Returns: bool

Math.PowerOfTwo(n)

Full Usage: Math.PowerOfTwo(n)

Parameters:
    n : float32

Returns: bool

Determines if a floating point number is a power of two.

n : float32
Returns: bool

Math.PowerOfTwo(n)

Full Usage: Math.PowerOfTwo(n)

Parameters:
    n : float

Returns: bool

Determines if a double precision floating point number is a power of two.

n : float
Returns: bool

Math.RollPitchYaw(angles)

Full Usage: Math.RollPitchYaw(angles)

Parameters:
Returns: Quaternion

Convert euler angles in [roll, pitch, yaw] to a quaternion. Sourced from - https://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles

angles : inref<Vector3>
Returns: Quaternion

Math.RollPitchYaw(rotation)

Full Usage: Math.RollPitchYaw(rotation)

Parameters:
Returns: Vector3

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.

rotation : inref<Quaternion>
Returns: Vector3

Math.SmoothStep(value1, value2, amount)

Full Usage: Math.SmoothStep(value1, value2, amount)

Parameters:
    value1 : float32 - Source value.
    value2 : float32 - Source value.
    amount : float32 - Weighting value.

Returns: float32 Interpolated value.

Interpolates between two values using a cubic equation.

value1 : float32

Source value.

value2 : float32

Source value.

amount : float32

Weighting value.

Returns: float32

Interpolated value.

Math.SmoothStep(value1, value2, amount)

Full Usage: Math.SmoothStep(value1, value2, amount)

Parameters:
    value1 : float - Source value.
    value2 : float - Source value.
    amount : float - Weighting value.

Returns: float Interpolated value.

Interpolates between two values using a cubic equation.

value1 : float

Source value.

value2 : float

Source value.

amount : float

Weighting value.

Returns: float

Interpolated value.

Math.Swap(a, b)

Full Usage: Math.Swap(a, b)

Parameters:
    a : byref<float> - The first value.
    b : byref<float> - The second value.

Swaps two double values.

a : byref<float>

The first value.

b : byref<float>

The second value.

Math.Swap(a, b)

Full Usage: Math.Swap(a, b)

Parameters:
    a : byref<float32> - The first value.
    b : byref<float32> - The second value.

Swaps two float values.

a : byref<float32>

The first value.

b : byref<float32>

The second value.

Math.ToDegrees(radians)

Full Usage: Math.ToDegrees(radians)

Parameters:
    radians : float32 - An angle in radians

Returns: float32 The angle expressed in degrees

Convert radians to degrees

radians : float32

An angle in radians

Returns: float32

The angle expressed in degrees

Math.ToDegrees(radians)

Full Usage: Math.ToDegrees(radians)

Parameters:
    radians : float - An angle in radians

Returns: float The angle expressed in degrees

Convert radians to degrees

radians : float

An angle in radians

Returns: float

The angle expressed in degrees

Math.ToRadians(degrees)

Full Usage: Math.ToRadians(degrees)

Parameters:
    degrees : float32 - An angle in degrees

Returns: float32 The angle expressed in radians

Convert degrees to radians

degrees : float32

An angle in degrees

Returns: float32

The angle expressed in radians

Math.ToRadians(degrees)

Full Usage: Math.ToRadians(degrees)

Parameters:
    degrees : float - An angle in degrees

Returns: float The angle expressed in radians

Convert degrees to radians

degrees : float

An angle in degrees

Returns: float

The angle expressed in radians

Type something to start searching.