Header menu logo Nu

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

MathHelper.Barycentric(value1, value2, value3, amount1, amount2)

Full Usage: MathHelper.Barycentric(value1, value2, value3, amount1, amount2)

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

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

MathHelper.CatmullRom(value1, value2, value3, value4, amount)

Full Usage: MathHelper.CatmullRom(value1, value2, value3, value4, amount)

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

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

MathHelper.Clamp(value, min, max)

Full Usage: MathHelper.Clamp(value, min, max)

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

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

MathHelper.Clamp(value, min, max)

Full Usage: MathHelper.Clamp(value, min, max)

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

Returns: int The clamped value.

Restricts a value to be within a specified range.

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.

Returns: int

The clamped value.

MathHelper.Distance(value1, value2)

Full Usage: MathHelper.Distance(value1, value2)

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

Returns: float32 Distance between the two values.

Calculates the absolute value of the difference of two values.

value1 : float32

Source value.

value2 : float32

Source value.

Returns: float32

Distance between the two values.

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

Full Usage: MathHelper.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.

MathHelper.IsPowerOfTwo(value)

Full Usage: MathHelper.IsPowerOfTwo(value)

Parameters:
    value : int - A value.

Returns: bool true if value is powered by two; otherwise false.

Determines if value is powered by two.

value : int

A value.

Returns: bool

true if value is powered by two; otherwise false.

MathHelper.Lerp(value1, value2, amount)

Full Usage: MathHelper.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 MathHelper.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.

MathHelper.LerpPrecise(value1, value2, amount)

Full Usage: MathHelper.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 MathHelper.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 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

value1 : float32

Source value.

value2 : float32

Destination value.

amount : float32

Value between 0 and 1 indicating the weight of value2.

Returns: float32

Interpolated value.

MathHelper.Max(value1, value2)

Full Usage: MathHelper.Max(value1, value2)

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

Returns: float32 The greater value.

Returns the greater of two values.

value1 : float32

Source value.

value2 : float32

Source value.

Returns: float32

The greater value.

MathHelper.Max(value1, value2)

Full Usage: MathHelper.Max(value1, value2)

Parameters:
    value1 : int - Source value.
    value2 : int - Source value.

Returns: int The greater value.

Returns the greater of two values.

value1 : int

Source value.

value2 : int

Source value.

Returns: int

The greater value.

MathHelper.Min(value1, value2)

Full Usage: MathHelper.Min(value1, value2)

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

Returns: float32 The lesser value.

Returns the lesser of two values.

value1 : float32

Source value.

value2 : float32

Source value.

Returns: float32

The lesser value.

MathHelper.Min(value1, value2)

Full Usage: MathHelper.Min(value1, value2)

Parameters:
    value1 : int - Source value.
    value2 : int - Source value.

Returns: int The lesser value.

Returns the lesser of two values.

value1 : int

Source value.

value2 : int

Source value.

Returns: int

The lesser value.

MathHelper.SmoothStep(value1, value2, amount)

Full Usage: MathHelper.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.

MathHelper.ToDegrees(radians)

Full Usage: MathHelper.ToDegrees(radians)

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

radians : float32

The angle in radians.

Returns: float32

The angle in degrees.

MathHelper.ToRadians(degrees)

Full Usage: MathHelper.ToRadians(degrees)

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

degrees : float32

The angle in degrees.

Returns: float32

The angle in radians.

MathHelper.WrapAngle(angle)

Full Usage: MathHelper.WrapAngle(angle)

Parameters:
    angle : float32 - The angle to reduce, in radians.

Returns: float32 The new angle, in radians.

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

angle : float32

The angle to reduce, in radians.

Returns: float32

The new angle, in radians.

Type something to start searching.