Nebula
Loading...
Searching...
No Matches
Mathf.MathHelper Class Reference

Detailed Description

Contains commonly used precalculated values and mathematical operations.

Static Public Member Functions

static float Barycentric (float value1, float value2, float value3, float amount1, float amount2)
 Returns the Cartesian coordinate for one axis of a point that is defined by a given triangle and two normalized barycentric (areal) coordinates.
 
static float CatmullRom (float value1, float value2, float value3, float value4, float amount)
 Performs a Catmull-Rom interpolation using the specified positions.
 
static float Clamp (float value, float min, float max)
 Restricts a value to be within a specified range.
 
static int Clamp (int value, int min, int max)
 Restricts a value to be within a specified range.
 
static float Distance (float value1, float value2)
 Calculates the absolute value of the difference of two values.
 
static float Hermite (float value1, float tangent1, float value2, float tangent2, float amount)
 Performs a Hermite spline interpolation.
 
static float Lerp (float value1, float value2, float amount)
 Linearly interpolates between two values.
 
static float LerpPrecise (float value1, float value2, float amount)
 Linearly interpolates between two values.
 
static float Max (float value1, float value2)
 Returns the greater of two values.
 
static int Max (int value1, int value2)
 Returns the greater of two values.
 
static float Min (float value1, float value2)
 Returns the lesser of two values.
 
static int Min (int value1, int value2)
 Returns the lesser of two values.
 
static float SmoothStep (float value1, float value2, float amount)
 Interpolates between two values using a cubic equation.
 
static float ToDegrees (float radians)
 Converts radians to degrees.
 
static float ToRadians (float degrees)
 Converts degrees to radians.
 
static float WrapAngle (float angle)
 Reduces a given angle to a value between π and -π.
 
static bool IsPowerOfTwo (int value)
 Determines if value is powered by two.
 

Static Public Attributes

const float E = (float)System.Math.E
 Represents the mathematical constant e(2.71828175).
 
const float Log10E = 0.4342945f
 Represents the log base ten of e(0.4342945).
 
const float Log2E = 1.442695f
 Represents the log base two of e(1.442695).
 
const float Pi = (float)System.Math.PI
 Represents the value of pi(3.14159274).
 
const float PiOver2 = (float)(System.Math.PI / 2.0)
 Represents the value of pi divided by two(1.57079637).
 
const float PiOver4 = (float)(System.Math.PI / 4.0)
 Represents the value of pi divided by four(0.7853982).
 
const float TwoPi = (float)(System.Math.PI * 2.0)
 Represents the value of pi times two(6.28318548).
 

Member Function Documentation

◆ Barycentric()

static float Mathf.MathHelper.Barycentric ( float value1,
float value2,
float value3,
float amount1,
float amount2 )
inlinestatic

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

Parameters
value1The coordinate on one axis of vertex 1 of the defining triangle.
value2The coordinate on the same axis of vertex 2 of the defining triangle.
value3The coordinate on the same axis of vertex 3 of the defining triangle.
amount1The normalized barycentric (areal) coordinate b2, equal to the weighting factor for vertex 2, the coordinate of which is specified in value2.
amount2The normalized barycentric (areal) coordinate b3, equal to the weighting factor for vertex 3, the coordinate of which is specified in value3.
Returns
Cartesian coordinate of the specified point with respect to the axis being used.

◆ CatmullRom()

static float Mathf.MathHelper.CatmullRom ( float value1,
float value2,
float value3,
float value4,
float amount )
inlinestatic

Performs a Catmull-Rom interpolation using the specified positions.

Parameters
value1The first position in the interpolation.
value2The second position in the interpolation.
value3The third position in the interpolation.
value4The fourth position in the interpolation.
amountWeighting factor.
Returns
A position that is the result of the Catmull-Rom interpolation.

◆ Clamp() [1/2]

static float Mathf.MathHelper.Clamp ( float value,
float min,
float max )
inlinestatic

Restricts a value to be within a specified range.

Parameters
valueThe value to clamp.
minThe minimum value. If value is less than min, min will be returned.
maxThe maximum value. If value is greater than max, max will be returned.
Returns
The clamped value.

◆ Clamp() [2/2]

static int Mathf.MathHelper.Clamp ( int value,
int min,
int max )
inlinestatic

Restricts a value to be within a specified range.

Parameters
valueThe value to clamp.
minThe minimum value. If value is less than min, min will be returned.
maxThe maximum value. If value is greater than max, max will be returned.
Returns
The clamped value.

◆ Distance()

static float Mathf.MathHelper.Distance ( float value1,
float value2 )
inlinestatic

Calculates the absolute value of the difference of two values.

Parameters
value1Source value.
value2Source value.
Returns
Distance between the two values.

◆ Hermite()

static float Mathf.MathHelper.Hermite ( float value1,
float tangent1,
float value2,
float tangent2,
float amount )
inlinestatic

Performs a Hermite spline interpolation.

Parameters
value1Source position.
tangent1Source tangent.
value2Source position.
tangent2Source tangent.
amountWeighting factor.
Returns
The result of the Hermite spline interpolation.

◆ IsPowerOfTwo()

static bool Mathf.MathHelper.IsPowerOfTwo ( int value)
inlinestatic

Determines if value is powered by two.

Parameters
valueA value.
Returns
true if value is powered by two; otherwise false.

◆ Lerp()

static float Mathf.MathHelper.Lerp ( float value1,
float value2,
float amount )
inlinestatic

Linearly interpolates between two values.

Parameters
value1Source value.
value2Destination value.
amountValue between 0 and 1 indicating the weight of value2.
Returns
Interpolated value.

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.

◆ LerpPrecise()

static float Mathf.MathHelper.LerpPrecise ( float value1,
float value2,
float amount )
inlinestatic

Linearly interpolates between two values.

This method is a less efficient, more precise version of MathHelper.Lerp. See remarks for more info.

Parameters
value1Source value.
value2Destination value.
amountValue between 0 and 1 indicating the weight of value2.
Returns
Interpolated value.

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

◆ Max() [1/2]

static float Mathf.MathHelper.Max ( float value1,
float value2 )
inlinestatic

Returns the greater of two values.

Parameters
value1Source value.
value2Source value.
Returns
The greater value.

◆ Max() [2/2]

static int Mathf.MathHelper.Max ( int value1,
int value2 )
inlinestatic

Returns the greater of two values.

Parameters
value1Source value.
value2Source value.
Returns
The greater value.

◆ Min() [1/2]

static float Mathf.MathHelper.Min ( float value1,
float value2 )
inlinestatic

Returns the lesser of two values.

Parameters
value1Source value.
value2Source value.
Returns
The lesser value.

◆ Min() [2/2]

static int Mathf.MathHelper.Min ( int value1,
int value2 )
inlinestatic

Returns the lesser of two values.

Parameters
value1Source value.
value2Source value.
Returns
The lesser value.

◆ SmoothStep()

static float Mathf.MathHelper.SmoothStep ( float value1,
float value2,
float amount )
inlinestatic

Interpolates between two values using a cubic equation.

Parameters
value1Source value.
value2Source value.
amountWeighting value.
Returns
Interpolated value.

◆ ToDegrees()

static float Mathf.MathHelper.ToDegrees ( float radians)
inlinestatic

Converts radians to degrees.

Parameters
radiansThe angle in radians.
Returns
The angle in degrees.

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

◆ ToRadians()

static float Mathf.MathHelper.ToRadians ( float degrees)
inlinestatic

Converts degrees to radians.

Parameters
degreesThe angle in degrees.
Returns
The angle in radians.

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

◆ WrapAngle()

static float Mathf.MathHelper.WrapAngle ( float angle)
inlinestatic

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

Parameters
angleThe angle to reduce, in radians.
Returns
The new angle, in radians.

Member Data Documentation

◆ E

const float Mathf.MathHelper.E = (float)System.Math.E
static

Represents the mathematical constant e(2.71828175).

◆ Log10E

const float Mathf.MathHelper.Log10E = 0.4342945f
static

Represents the log base ten of e(0.4342945).

◆ Log2E

const float Mathf.MathHelper.Log2E = 1.442695f
static

Represents the log base two of e(1.442695).

◆ Pi

const float Mathf.MathHelper.Pi = (float)System.Math.PI
static

Represents the value of pi(3.14159274).

◆ PiOver2

const float Mathf.MathHelper.PiOver2 = (float)(System.Math.PI / 2.0)
static

Represents the value of pi divided by two(1.57079637).

◆ PiOver4

const float Mathf.MathHelper.PiOver4 = (float)(System.Math.PI / 4.0)
static

Represents the value of pi divided by four(0.7853982).

◆ TwoPi

const float Mathf.MathHelper.TwoPi = (float)(System.Math.PI * 2.0)
static

Represents the value of pi times two(6.28318548).


The documentation for this class was generated from the following file: