Shift
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Pages
Shift.MathHelper Class Reference

Contains commonly used precalculated values and mathematical operations. More...

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. More...
 
static float CatmullRom (float value1, float value2, float value3, float value4, float amount)
 Performs a Catmull-Rom interpolation using the specified positions. More...
 
static float Clamp (float value, float min, float max)
 Restricts a value to be within a specified range. More...
 
static int Clamp (int value, int min, int max)
 Restricts a value to be within a specified range. More...
 
static float Distance (float value1, float value2)
 Calculates the absolute value of the difference of two values. More...
 
static float Hermite (float value1, float tangent1, float value2, float tangent2, float amount)
 Performs a Hermite spline interpolation. More...
 
static float Lerp (float value1, float value2, float amount)
 Linearly interpolates between two values. More...
 
static float LerpPrecise (float value1, float value2, float amount)
 Linearly interpolates between two values. This method is a less efficient, more precise version of MathHelper.Lerp. See remarks for more info. More...
 
static float Max (float value1, float value2)
 Returns the greater of two values. More...
 
static int Max (int value1, int value2)
 Returns the greater of two values. More...
 
static float Min (float value1, float value2)
 Returns the lesser of two values. More...
 
static int Min (int value1, int value2)
 Returns the lesser of two values. More...
 
static float SmoothStep (float value1, float value2, float amount)
 Interpolates between two values using a cubic equation. More...
 
static float ToDegrees (float radians)
 Converts radians to degrees. More...
 
static float ToRadians (float degrees)
 Converts degrees to radians. More...
 
static float WrapAngle (float angle)
 Reduces a given angle to a value between π and -π. More...
 
static bool IsPowerOfTwo (int value)
 Determines if value is powered by two. More...
 

Public Attributes

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

Detailed Description

Contains commonly used precalculated values and mathematical operations.

Definition at line 8 of file MathHelper.cs.

Member Function Documentation

static float Shift.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.

Definition at line 54 of file MathHelper.cs.

static float Shift.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.

Definition at line 68 of file MathHelper.cs.

static float Shift.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.

Definition at line 87 of file MathHelper.cs.

static int Shift.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.

Definition at line 106 of file MathHelper.cs.

static float Shift.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.

Definition at line 119 of file MathHelper.cs.

static float Shift.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.

Definition at line 133 of file MathHelper.cs.

static bool Shift.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.

Definition at line 316 of file MathHelper.cs.

static float Shift.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.

Definition at line 166 of file MathHelper.cs.

static float Shift.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

Definition at line 192 of file MathHelper.cs.

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

Returns the greater of two values.

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

Definition at line 203 of file MathHelper.cs.

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

Returns the greater of two values.

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

Definition at line 214 of file MathHelper.cs.

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

Returns the lesser of two values.

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

Definition at line 225 of file MathHelper.cs.

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

Returns the lesser of two values.

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

Definition at line 236 of file MathHelper.cs.

static float Shift.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.

Definition at line 248 of file MathHelper.cs.

static float Shift.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

Definition at line 269 of file MathHelper.cs.

static float Shift.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

Definition at line 284 of file MathHelper.cs.

static float Shift.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.

Definition at line 294 of file MathHelper.cs.

Member Data Documentation

const float Shift.MathHelper.E = (float)Math.E

Represents the mathematical constant e(2.71828175).

Definition at line 13 of file MathHelper.cs.

const float Shift.MathHelper.Log10E = 0.4342945f

Represents the log base ten of e(0.4342945).

Definition at line 18 of file MathHelper.cs.

const float Shift.MathHelper.Log2E = 1.442695f

Represents the log base two of e(1.442695).

Definition at line 23 of file MathHelper.cs.

const float Shift.MathHelper.Pi = (float)Math.PI

Represents the value of pi(3.14159274).

Definition at line 28 of file MathHelper.cs.

const float Shift.MathHelper.PiOver2 = (float)(Math.PI / 2.0)

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

Definition at line 33 of file MathHelper.cs.

const float Shift.MathHelper.PiOver4 = (float)(Math.PI / 4.0)

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

Definition at line 38 of file MathHelper.cs.

const float Shift.MathHelper.TwoPi = (float)(Math.PI * 2.0)

Represents the value of pi times two(6.28318548).

Definition at line 43 of file MathHelper.cs.


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