Class MathHelper
Math helper functions.
Inherited Members
Namespace: Evergine.Mathematics
Assembly: Evergine.Mathematics.dll
Syntax
public static class MathHelper
  Fields
E
Represents the mathematical constant e.
Declaration
public const float E = 2.7182817
  Field Value
| Type | Description | 
|---|---|
| float | 
Epsilon
The epsilon.
Declaration
public const float Epsilon = 1.1920929E-07
  Field Value
| Type | Description | 
|---|---|
| float | 
Log10E
Represents the log base ten of e.
Declaration
public const float Log10E = 0.4342945
  Field Value
| Type | Description | 
|---|---|
| float | 
Log2E
Represents the log base two of e.
Declaration
public const float Log2E = 1.442695
  Field Value
| Type | Description | 
|---|---|
| float | 
Pi
Represents the value of pi.
Declaration
public const float Pi = 3.1415927
  Field Value
| Type | Description | 
|---|---|
| float | 
PiOver2
Represents the value of pi divided by two.
Declaration
public const float PiOver2 = 1.5707964
  Field Value
| Type | Description | 
|---|---|
| float | 
PiOver4
Represents the value of pi divided by four.
Declaration
public const float PiOver4 = 0.7853982
  Field Value
| Type | Description | 
|---|---|
| float | 
TwoPi
Represents the value of pi times two.
Declaration
public const float TwoPi = 6.2831855
  Field Value
| Type | Description | 
|---|---|
| float | 
Properties
SimdType
Gets the type of SIMD instructions used.
Declaration
public static MathSimdType SimdType { get; }
  Property Value
| Type | Description | 
|---|---|
| MathSimdType | 
Methods
Area(ref Vector2, ref Vector2, ref Vector2)
Linearly interpolates between value1 and value2 by amount. The parameter amount is not clamped and values outside the range [0, 1] will result in a return value outside the range [value1, value2]. Returns a positive number if c is to the left of the line going from a to b.
Declaration
public static float Area(ref Vector2 a, ref Vector2 b, ref Vector2 c)
  Parameters
| Type | Name | Description | 
|---|---|---|
| Vector2 | a | The first vector.  | 
      
| Vector2 | b | The second vector.  | 
      
| Vector2 | c | The third vector.  | 
      
Returns
| Type | Description | 
|---|---|
| float | Positive number if point is left, negative if point is right, and 0 if points are collinear.  | 
      
Barycentric(float, float, float, float, float)
Returns the Cartesian coordinate for one axis of a point that is defined by a given triangle and two normalized barycentric (areal) coordinates.
Declaration
public static float Barycentric(float value1, float value2, float value3, float amount1, float amount2)
  Parameters
| Type | Name | Description | 
|---|---|---|
| float | value1 | The coordinate on one axis of vertex 1 of the defining triangle.  | 
      
| float | value2 | The coordinate on the same axis of vertex 2 of the defining triangle.  | 
      
| float | value3 | The coordinate on the same axis of vertex 3 of the defining triangle.  | 
      
| float | amount1 | The normalized barycentric (areal) coordinate b2, equal to the weighting factor for vertex 2, the coordinate of which is specified in value2.  | 
      
| float | amount2 | The normalized barycentric (areal) coordinate b3, equal to the weighting factor for vertex 3, the coordinate of which is specified in value3.  | 
      
Returns
| Type | Description | 
|---|---|
| float | Cartesian coordinate of the specified point with respect to the axis being used.  | 
      
CatmullRom(float, float, float, float, float)
Performs a Catmull-Rom interpolation using the specified positions.
Declaration
public static float CatmullRom(float value1, float value2, float value3, float value4, float amount)
  Parameters
| Type | Name | Description | 
|---|---|---|
| float | value1 | The first position in the interpolation.  | 
      
| float | value2 | The second position in the interpolation.  | 
      
| float | value3 | The third position in the interpolation.  | 
      
| float | value4 | The fourth position in the interpolation.  | 
      
| float | amount | Weighting factor.  | 
      
Returns
| Type | Description | 
|---|---|
| float | A position that is the result of the Catmull-Rom interpolation.  | 
      
Clamp(float, float, float)
Clamps a value between a minimum float and maximum float value.
Declaration
public static float Clamp(float value, float min, float max)
  Parameters
| Type | Name | Description | 
|---|---|---|
| float | value | The value.  | 
      
| float | min | The minimum value. If value is less than min, min will be returned.  | 
      
| float | max | The maximum value. If value is greater than max, max will be returned.  | 
      
Returns
| Type | Description | 
|---|---|
| float | The clamped value.  | 
      
Distance(float, float)
Calculates the absolute value of the difference of two values.
Declaration
public static float Distance(float value1, float value2)
  Parameters
| Type | Name | Description | 
|---|---|---|
| float | value1 | Source value1.  | 
      
| float | value2 | Source value2.  | 
      
Returns
| Type | Description | 
|---|---|
| float | Distance between the two values.  | 
      
DivideByMultiple(uint, uint)
Divide value by alignment to get the minimum multiple higher than the value.
Declaration
public static uint DivideByMultiple(uint value, uint alignment)
  Parameters
| Type | Name | Description | 
|---|---|---|
| uint | value | The value to divide.  | 
      
| uint | alignment | The alignment.  | 
      
Returns
| Type | Description | 
|---|---|
| uint | The multiply value.  | 
      
FloatEquals(float, float)
Checks if a floating point Value is equal to another, within a certain tolerance.
Declaration
public static bool FloatEquals(float value1, float value2)
  Parameters
| Type | Name | Description | 
|---|---|---|
| float | value1 | The first floating point Value.  | 
      
| float | value2 | The second floating point Value.  | 
      
Returns
| Type | Description | 
|---|---|
| bool | True if the values are "equal", false otherwise.  | 
      
FloatEquals(float, float, float)
Checks if a floating point Value is equal to another, within a certain tolerance.
Declaration
public static bool FloatEquals(float value1, float value2, float delta)
  Parameters
| Type | Name | Description | 
|---|---|---|
| float | value1 | The first floating point Value.  | 
      
| float | value2 | The second floating point Value.  | 
      
| float | delta | The floating point tolerance.  | 
      
Returns
| Type | Description | 
|---|---|
| bool | True if the values are "equal", false otherwise.  | 
      
FloatInRange(float, float, float)
Checks if a floating point Value is within a specified range of values (inclusive).
Declaration
public static bool FloatInRange(float value, float min, float max)
  Parameters
| Type | Name | Description | 
|---|---|---|
| float | value | The Value to check.  | 
      
| float | min | The minimum Value.  | 
      
| float | max | The maximum Value.  | 
      
Returns
| Type | Description | 
|---|---|
| bool | True if the Value is within the range specified, false otherwise.  | 
      
Hermite(float, float, float, float, float)
Performs a Hermite spline interpolation.
Declaration
public static float Hermite(float value1, float tangent1, float value2, float tangent2, float amount)
  Parameters
| Type | Name | Description | 
|---|---|---|
| float | value1 | Source value1.  | 
      
| float | tangent1 | Source tangent1.  | 
      
| float | value2 | Source value2.  | 
      
| float | tangent2 | Source tangent2.  | 
      
| float | amount | Weighting factor.  | 
      
Returns
| Type | Description | 
|---|---|
| float | The result of the Hermite spline interpolation.  | 
      
InverseLerp(float, float, float)
Calculates the linear parameter amount that produces the interpolant value within the range [value1, value2].
Declaration
public static float InverseLerp(float value1, float value2, float value)
  Parameters
| Type | Name | Description | 
|---|---|---|
| float | value1 | Source value1.  | 
      
| float | value2 | Source value2.  | 
      
| float | value | Interpolant value.  | 
      
Returns
| Type | Description | 
|---|---|
| float | The linear parameter amount.  | 
      
Lerp(float, float, float)
Lerps the specified value1.
Declaration
public static float Lerp(float value1, float value2, float amount)
  Parameters
| Type | Name | Description | 
|---|---|---|
| float | value1 | The value1.  | 
      
| float | value2 | The value2.  | 
      
| float | amount | The amount.  | 
      
Returns
| Type | Description | 
|---|---|
| float | Interpolated value.  | 
      
Examples
When amount = 0 returns value1. When amount = 1 return value2. When amount = 0.5 returns the midpoint of value1 and value2.
LerpClamped(float, float, float)
Linearly interpolates between value1 and value2 by amount. The parameter amount is clamped to the range [0, 1].
Declaration
public static float LerpClamped(float value1, float value2, float amount)
  Parameters
| Type | Name | Description | 
|---|---|---|
| float | value1 | Source value1.  | 
      
| float | value2 | Source value2.  | 
      
| float | amount | Value between 0 and 1 indicating the weight of value2.  | 
      
Returns
| Type | Description | 
|---|---|
| float | Interpolated value.  | 
      
Examples
When amount = 0 returns value1. When amount = 1 return value2. When amount = 0.5 returns the midpoint of value1 and value2.
Max(ref Vector2)
Returns the greater of two Vector2 components.
Declaration
public static float Max(ref Vector2 value)
  Parameters
| Type | Name | Description | 
|---|---|---|
| Vector2 | value | Source value.  | 
      
Returns
| Type | Description | 
|---|---|
| float | The greater value.  | 
      
Max(ref Vector3)
Returns the greater of three Vector3 components.
Declaration
public static float Max(ref Vector3 value)
  Parameters
| Type | Name | Description | 
|---|---|---|
| Vector3 | value | Source vector.  | 
      
Returns
| Type | Description | 
|---|---|
| float | The greater value.  | 
      
Max(int, int)
Returns the greater of two int values.
Declaration
public static int Max(int value1, int value2)
  Parameters
| Type | Name | Description | 
|---|---|---|
| int | value1 | Source value1.  | 
      
| int | value2 | Source value2.  | 
      
Returns
| Type | Description | 
|---|---|
| int | The greater value.  | 
      
Max(float, float)
Returns the greater of two float values.
Declaration
public static float Max(float value1, float value2)
  Parameters
| Type | Name | Description | 
|---|---|---|
| float | value1 | Source value1.  | 
      
| float | value2 | Source value2.  | 
      
Returns
| Type | Description | 
|---|---|
| float | The greater value.  | 
      
Min(ref Vector2)
Returns the lesser of two Vector2 components.
Declaration
public static float Min(ref Vector2 value)
  Parameters
| Type | Name | Description | 
|---|---|---|
| Vector2 | value | Source value.  | 
      
Returns
| Type | Description | 
|---|---|
| float | The lesser value.  | 
      
Min(ref Vector3)
Returns the lesser of three Vector3 components.
Declaration
public static float Min(ref Vector3 value)
  Parameters
| Type | Name | Description | 
|---|---|---|
| Vector3 | value | Source vector.  | 
      
Returns
| Type | Description | 
|---|---|
| float | The lesser value.  | 
      
Min(float, float)
Returns the lesser of two or more values.
Declaration
public static float Min(float value1, float value2)
  Parameters
| Type | Name | Description | 
|---|---|---|
| float | value1 | Source value1.  | 
      
| float | value2 | Source value2.  | 
      
Returns
| Type | Description | 
|---|---|
| float | The lesser value.  | 
      
NextPowerOfTwo(int)
Return the next power of two value of the specified argument.
Declaration
public static int NextPowerOfTwo(int v)
  Parameters
| Type | Name | Description | 
|---|---|---|
| int | v | The value.  | 
      
Returns
| Type | Description | 
|---|---|
| int | The next power of two.  | 
      
NextPowerOfTwo(ulong)
Return the next power of two value of the specified argument.
Declaration
public static ulong NextPowerOfTwo(ulong v)
  Parameters
| Type | Name | Description | 
|---|---|---|
| ulong | v | The value.  | 
      
Returns
| Type | Description | 
|---|---|
| ulong | The next power of two.  | 
      
SmoothDamp(float, float, ref float, float, float)
Changes a float value towards a desired goal over time.
Declaration
public static float SmoothDamp(float current, float target, ref float currentVelocity, float smoothTime, float gameTime)
  Parameters
| Type | Name | Description | 
|---|---|---|
| float | current | The current value.  | 
      
| float | target | The target value.  | 
      
| float | currentVelocity | The current velocity.  | 
      
| float | smoothTime | The time it will take to reach the target.  | 
      
| float | gameTime | The current game time (time between last frame).  | 
      
Returns
| Type | Description | 
|---|---|
| float | The smooth value.  | 
      
SmoothStep(float, float, float)
Interpolates between two values using a cubic equation.
Declaration
public static float SmoothStep(float value1, float value2, float amount)
  Parameters
| Type | Name | Description | 
|---|---|---|
| float | value1 | Source value1.  | 
      
| float | value2 | Source value2.  | 
      
| float | amount | Weighting value.  | 
      
Returns
| Type | Description | 
|---|---|
| float | Interpolated value.  | 
      
ToDegrees(double)
Converts radians to degrees.
Declaration
public static float ToDegrees(double radians)
  Parameters
| Type | Name | Description | 
|---|---|---|
| double | radians | The angle in radians.  | 
      
Returns
| Type | Description | 
|---|---|
| float | The angle in degrees.  | 
      
ToDegrees(float)
Converts radians to degrees.
Declaration
public static float ToDegrees(float radians)
  Parameters
| Type | Name | Description | 
|---|---|---|
| float | radians | The angle in radians.  | 
      
Returns
| Type | Description | 
|---|---|
| float | The angle in degrees.  | 
      
ToRadians(double)
Converts degrees to radians.
Declaration
public static float ToRadians(double degrees)
  Parameters
| Type | Name | Description | 
|---|---|---|
| double | degrees | The angle in degrees..  | 
      
Returns
| Type | Description | 
|---|---|
| float | The angle in radians.  | 
      
ToRadians(float)
Converts degrees to radians.
Declaration
public static float ToRadians(float degrees)
  Parameters
| Type | Name | Description | 
|---|---|---|
| float | degrees | The angle in degrees.  | 
      
Returns
| Type | Description | 
|---|---|
| float | The angle in radians.  | 
      
WrapAngle(float)
Reduces a given angle to a value between π and -π.
Declaration
public static float WrapAngle(float angle)
  Parameters
| Type | Name | Description | 
|---|---|---|
| float | angle | The angle to reduce, in radians.  | 
      
Returns
| Type | Description | 
|---|---|
| float | The new angle, in radians.  |