Show / Hide Table of Contents

Class MathHelper

Contains commonly used precalculated values.

Inheritance
System.Object
MathHelper
Namespace: VRageMath
Assembly: VRage.Math.dll
Syntax
public static class MathHelper : Object

Fields

E

Represents the mathematical constant e.

Declaration
public const float E = 2.718282F
Field Value
Type Description
System.Single

EPSILON

Declaration
public const float EPSILON = 1E-05F
Field Value
Type Description
System.Single

EPSILON10

Declaration
public const float EPSILON10 = 1E-06F
Field Value
Type Description
System.Single

FourPi

Represents the value of pi times two.

Declaration
public const float FourPi = 12.566371F
Field Value
Type Description
System.Single

Log10E

Represents the log base ten of e.

Declaration
public const float Log10E = 0.4342945F
Field Value
Type Description
System.Single

Log2E

Represents the log base two of e.

Declaration
public const float Log2E = 1.442695F
Field Value
Type Description
System.Single

Pi

Represents the value of pi.

Declaration
public const float Pi = 3.141593F
Field Value
Type Description
System.Single

PiOver2

Represents the value of pi divided by two.

Declaration
public const float PiOver2 = 1.570796F
Field Value
Type Description
System.Single

PiOver4

Represents the value of pi divided by four.

Declaration
public const float PiOver4 = 0.7853982F
Field Value
Type Description
System.Single

RadiansPerSecondToRPM

60 / 2*pi

Declaration
public const float RadiansPerSecondToRPM = 9.549296F
Field Value
Type Description
System.Single

RPMToRadiansPerMillisec

2*pi / 60000

Declaration
public const float RPMToRadiansPerMillisec = 0.000104719758F
Field Value
Type Description
System.Single

RPMToRadiansPerSecond

2*pi / 60

Declaration
public const float RPMToRadiansPerSecond = 0.104719758F
Field Value
Type Description
System.Single

Sqrt2

Represents the value of the square root of two

Declaration
public const float Sqrt2 = 1.41421354F
Field Value
Type Description
System.Single

Sqrt3

Represents the value of the square root of three

Declaration
public const float Sqrt3 = 1.73205078F
Field Value
Type Description
System.Single

TwoPi

Represents the value of pi times two.

Declaration
public const float TwoPi = 6.28318548F
Field Value
Type Description
System.Single

Methods

Align(Int32, Int32)

Declaration
public static int Align(int value, int alignment)
Parameters
Type Name Description
System.Int32 value
System.Int32 alignment
Returns
Type Description
System.Int32

Atan(Double)

Faster Atan implementation.

Good only in the [-pi/2, pi/2] range.

Declaration
public static double Atan(double x)
Parameters
Type Name Description
System.Double x
Returns
Type Description
System.Double

Atan(Single)

Faster Atan implementation.

Good only in the [-pi/2, pi/2] range.

Declaration
public static float Atan(float x)
Parameters
Type Name Description
System.Single x
Returns
Type Description
System.Single

Barycentric(Single, Single, Single, Single, Single)

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
System.Single value1

The coordinate on one axis of vertex 1 of the defining triangle.

System.Single value2

The coordinate on the same axis of vertex 2 of the defining triangle.

System.Single value3

The coordinate on the same axis of vertex 3 of the defining triangle.

System.Single amount1

The normalized barycentric (areal) coordinate b2, equal to the weighting factor for vertex 2, the coordinate of which is specified in value2.

System.Single 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
System.Single

CalculateBezierPoint(Double, Vector3D, Vector3D, Vector3D, Vector3D)

Declaration
public static Vector3D CalculateBezierPoint(double t, Vector3D p0, Vector3D p1, Vector3D p2, Vector3D p3)
Parameters
Type Name Description
System.Double t
Vector3D p0
Vector3D p1
Vector3D p2
Vector3D p3
Returns
Type Description
Vector3D

CalculateVectorOnSphere(Vector3, Single, Single)

Declaration
public static Vector3 CalculateVectorOnSphere(Vector3 northPoleDir, float phi, float theta)
Parameters
Type Name Description
Vector3 northPoleDir
System.Single phi
System.Single theta
Returns
Type Description
Vector3

CatmullRom(Single, Single, Single, Single, Single)

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
System.Single value1

The first position in the interpolation.

System.Single value2

The second position in the interpolation.

System.Single value3

The third position in the interpolation.

System.Single value4

The fourth position in the interpolation.

System.Single amount

Weighting factor.

Returns
Type Description
System.Single

CeilToInt(Double)

Declaration
public static int CeilToInt(double x)
Parameters
Type Name Description
System.Double x
Returns
Type Description
System.Int32

CeilToInt(Single)

Declaration
public static int CeilToInt(float x)
Parameters
Type Name Description
System.Single x
Returns
Type Description
System.Int32

Clamp(Byte, Byte, Byte)

Restricts a value to be within a specified range.

Declaration
public static byte Clamp(byte value, byte min, byte max)
Parameters
Type Name Description
System.Byte value

The value to clamp.

System.Byte min

The minimum value. If value is less than min, min will be returned.

System.Byte max

The maximum value. If value is greater than max, max will be returned.

Returns
Type Description
System.Byte

Clamp(Double, Double, Double)

Restricts a value to be within a specified range. Reference page contains links to related code samples.

Declaration
public static double Clamp(double value, double min, double max)
Parameters
Type Name Description
System.Double value

The value to clamp.

System.Double min

The minimum value. If value is less than min, min will be returned.

System.Double max

The maximum value. If value is greater than max, max will be returned.

Returns
Type Description
System.Double

Clamp(Int32, Int32, Int32)

Restricts a value to be within a specified range. Reference page contains links to related code samples.

Declaration
public static int Clamp(int value, int min, int max)
Parameters
Type Name Description
System.Int32 value

The value to clamp.

System.Int32 min

The minimum value. If value is less than min, min will be returned.

System.Int32 max

The maximum value. If value is greater than max, max will be returned.

Returns
Type Description
System.Int32

Clamp(Single, Single, Single)

Restricts a value to be within a specified range. Reference page contains links to related code samples.

Declaration
public static float Clamp(float value, float min, float max)
Parameters
Type Name Description
System.Single value

The value to clamp.

System.Single min

The minimum value. If value is less than min, min will be returned.

System.Single max

The maximum value. If value is greater than max, max will be returned.

Returns
Type Description
System.Single

Clamp(MyFixedPoint, MyFixedPoint, MyFixedPoint)

Restricts a value to be within a specified range. Reference page contains links to related code samples.

Declaration
public static MyFixedPoint Clamp(MyFixedPoint value, MyFixedPoint min, MyFixedPoint max)
Parameters
Type Name Description
VRage.MyFixedPoint value

The value to clamp.

VRage.MyFixedPoint min

The minimum value. If value is less than min, min will be returned.

VRage.MyFixedPoint max

The maximum value. If value is greater than max, max will be returned.

Returns
Type Description
VRage.MyFixedPoint

ComputeHashFromBytes(Byte[])

Declaration
public static int ComputeHashFromBytes(byte[] bytes)
Parameters
Type Name Description
System.Byte[] bytes
Returns
Type Description
System.Int32

CubicInterp(Double, Double, Double, Double, Double)

Declaration
public static double CubicInterp(double p0, double p1, double p2, double p3, double t)
Parameters
Type Name Description
System.Double p0
System.Double p1
System.Double p2
System.Double p3
System.Double t
Returns
Type Description
System.Double

Distance(Single, Single)

Calculates the absolute value of the difference of two values.

Declaration
public static float Distance(float value1, float value2)
Parameters
Type Name Description
System.Single value1

Source value.

System.Single value2

Source value.

Returns
Type Description
System.Single

Floor(Double)

Declaration
public static int Floor(double n)
Parameters
Type Name Description
System.Double n
Returns
Type Description
System.Int32

Floor(Single)

Declaration
public static int Floor(float n)
Parameters
Type Name Description
System.Single n
Returns
Type Description
System.Int32

FloorToInt(Double)

Declaration
public static int FloorToInt(double x)
Parameters
Type Name Description
System.Double x
Returns
Type Description
System.Int32

FloorToInt(Single)

Declaration
public static int FloorToInt(float x)
Parameters
Type Name Description
System.Single x
Returns
Type Description
System.Int32

GetNearestBiggerPowerOfTwo(Double)

Declaration
public static int GetNearestBiggerPowerOfTwo(double f)
Parameters
Type Name Description
System.Double f
Returns
Type Description
System.Int32

GetNearestBiggerPowerOfTwo(Int32)

Declaration
public static int GetNearestBiggerPowerOfTwo(int v)
Parameters
Type Name Description
System.Int32 v
Returns
Type Description
System.Int32

GetNearestBiggerPowerOfTwo(Single)

Returns nearest bigger power of two

Declaration
public static int GetNearestBiggerPowerOfTwo(float f)
Parameters
Type Name Description
System.Single f
Returns
Type Description
System.Int32

GetNearestBiggerPowerOfTwo(UInt32)

Declaration
public static uint GetNearestBiggerPowerOfTwo(uint v)
Parameters
Type Name Description
System.UInt32 v
Returns
Type Description
System.UInt32

GetNumberOfMipmaps(Int32)

Declaration
public static int GetNumberOfMipmaps(int v)
Parameters
Type Name Description
System.Int32 v
Returns
Type Description
System.Int32

Hermite(Single, Single, Single, Single, Single)

Performs a Hermite spline interpolation.

Declaration
public static float Hermite(float value1, float tangent1, float value2, float tangent2, float amount)
Parameters
Type Name Description
System.Single value1

Source position.

System.Single tangent1

Source tangent.

System.Single value2

Source position.

System.Single tangent2

Source tangent.

System.Single amount

Weighting factor.

Returns
Type Description
System.Single

InterpLog(Single, Single, Single)

Performs interpolation on logarithmic scale.

Declaration
public static float InterpLog(float value, float amount1, float amount2)
Parameters
Type Name Description
System.Single value
System.Single amount1
System.Single amount2
Returns
Type Description
System.Single

InterpLogInv(Single, Single, Single)

Declaration
public static float InterpLogInv(float value, float amount1, float amount2)
Parameters
Type Name Description
System.Single value
System.Single amount1
System.Single amount2
Returns
Type Description
System.Single

IsEqual(Single, Single)

Declaration
public static bool IsEqual(float value1, float value2)
Parameters
Type Name Description
System.Single value1
System.Single value2
Returns
Type Description
System.Boolean

IsEqual(Matrix, Matrix)

Declaration
public static bool IsEqual(Matrix value1, Matrix value2)
Parameters
Type Name Description
Matrix value1
Matrix value2
Returns
Type Description
System.Boolean

IsEqual(Quaternion, Quaternion)

Declaration
public static bool IsEqual(Quaternion value1, Quaternion value2)
Parameters
Type Name Description
Quaternion value1
Quaternion value2
Returns
Type Description
System.Boolean

IsEqual(QuaternionD, QuaternionD)

Declaration
public static bool IsEqual(QuaternionD value1, QuaternionD value2)
Parameters
Type Name Description
QuaternionD value1
QuaternionD value2
Returns
Type Description
System.Boolean

IsEqual(Vector2, Vector2)

Declaration
public static bool IsEqual(Vector2 value1, Vector2 value2)
Parameters
Type Name Description
Vector2 value1
Vector2 value2
Returns
Type Description
System.Boolean

IsEqual(Vector3, Vector3)

Declaration
public static bool IsEqual(Vector3 value1, Vector3 value2)
Parameters
Type Name Description
Vector3 value1
Vector3 value2
Returns
Type Description
System.Boolean

IsPowerOfTwo(Int32)

Returns true if value is power of two

Declaration
public static bool IsPowerOfTwo(int x)
Parameters
Type Name Description
System.Int32 x
Returns
Type Description
System.Boolean

IsValid(Double)

Declaration
public static bool IsValid(double f)
Parameters
Type Name Description
System.Double f
Returns
Type Description
System.Boolean

IsValid(Nullable<Vector3>)

Declaration
public static bool IsValid(Nullable<Vector3> vec)
Parameters
Type Name Description
System.Nullable<Vector3> vec
Returns
Type Description
System.Boolean

IsValid(Single)

Declaration
public static bool IsValid(float f)
Parameters
Type Name Description
System.Single f
Returns
Type Description
System.Boolean

IsValid(Matrix)

Declaration
public static bool IsValid(Matrix matrix)
Parameters
Type Name Description
Matrix matrix
Returns
Type Description
System.Boolean

IsValid(MatrixD)

Declaration
public static bool IsValid(MatrixD matrix)
Parameters
Type Name Description
MatrixD matrix
Returns
Type Description
System.Boolean

IsValid(Quaternion)

Declaration
public static bool IsValid(Quaternion q)
Parameters
Type Name Description
Quaternion q
Returns
Type Description
System.Boolean

IsValid(Vector2)

Declaration
public static bool IsValid(Vector2 vec)
Parameters
Type Name Description
Vector2 vec
Returns
Type Description
System.Boolean

IsValid(Vector3)

Declaration
public static bool IsValid(Vector3 vec)
Parameters
Type Name Description
Vector3 vec
Returns
Type Description
System.Boolean

IsValid(Vector3D)

Declaration
public static bool IsValid(Vector3D vec)
Parameters
Type Name Description
Vector3D vec
Returns
Type Description
System.Boolean

IsValidNormal(Vector3)

Declaration
public static bool IsValidNormal(Vector3 vec)
Parameters
Type Name Description
Vector3 vec
Returns
Type Description
System.Boolean

IsValidOrZero(Matrix)

Declaration
public static bool IsValidOrZero(Matrix matrix)
Parameters
Type Name Description
Matrix matrix
Returns
Type Description
System.Boolean

IsZero(Double, Single)

Declaration
public static bool IsZero(double value, float epsilon = 1E-05F)
Parameters
Type Name Description
System.Double value
System.Single epsilon
Returns
Type Description
System.Boolean

IsZero(Single, Single)

Declaration
public static bool IsZero(float value, float epsilon = 1E-05F)
Parameters
Type Name Description
System.Single value
System.Single epsilon
Returns
Type Description
System.Boolean

IsZero(Quaternion, Single)

Declaration
public static bool IsZero(Quaternion value, float epsilon = 1E-05F)
Parameters
Type Name Description
Quaternion value
System.Single epsilon
Returns
Type Description
System.Boolean

IsZero(Vector3, Single)

Declaration
public static bool IsZero(Vector3 value, float epsilon = 1E-05F)
Parameters
Type Name Description
Vector3 value
System.Single epsilon
Returns
Type Description
System.Boolean

IsZero(Vector3D, Single)

Declaration
public static bool IsZero(Vector3D value, float epsilon = 1E-05F)
Parameters
Type Name Description
Vector3D value
System.Single epsilon
Returns
Type Description
System.Boolean

IsZero(Vector4)

Declaration
public static bool IsZero(Vector4 value)
Parameters
Type Name Description
Vector4 value
Returns
Type Description
System.Boolean

Lerp(Double, Double, Double)

Linearly interpolates between two values.

Declaration
public static double Lerp(double value1, double value2, double amount)
Parameters
Type Name Description
System.Double value1

Source value.

System.Double value2

Source value.

System.Double amount

Value between 0 and 1 indicating the weight of value2.

Returns
Type Description
System.Double

Lerp(Single, Single, Single)

Linearly interpolates between two values.

Declaration
public static float Lerp(float value1, float value2, float amount)
Parameters
Type Name Description
System.Single value1

Source value.

System.Single value2

Source value.

System.Single amount

Value between 0 and 1 indicating the weight of value2.

Returns
Type Description
System.Single

LimitRadians(ref Single)

Returns angle in range 0..2*PI

Declaration
public static void LimitRadians(ref float angle)
Parameters
Type Name Description
System.Single angle

in radians

LimitRadians2PI(ref Double)

Returns angle in range 0..2*PI

Declaration
public static void LimitRadians2PI(ref double angle)
Parameters
Type Name Description
System.Double angle

in radians

LimitRadiansPI(ref Double)

Returns angle in range -PI..PI

Declaration
public static void LimitRadiansPI(ref double angle)
Parameters
Type Name Description
System.Double angle

radians

LimitRadiansPI(ref Single)

Returns angle in range -PI..PI

Declaration
public static void LimitRadiansPI(ref float angle)
Parameters
Type Name Description
System.Single angle

radians

Log2(Int32)

Declaration
public static int Log2(int n)
Parameters
Type Name Description
System.Int32 n
Returns
Type Description
System.Int32

Log2(UInt32)

Declaration
public static int Log2(uint n)
Parameters
Type Name Description
System.UInt32 n
Returns
Type Description
System.Int32

Log2Ceiling(Int32)

Declaration
public static int Log2Ceiling(int value)
Parameters
Type Name Description
System.Int32 value
Returns
Type Description
System.Int32

Log2Floor(Int32)

Declaration
public static int Log2Floor(int value)
Parameters
Type Name Description
System.Int32 value
Returns
Type Description
System.Int32

Max(Double, Double)

Returns the greater of two values.

Declaration
public static double Max(double value1, double value2)
Parameters
Type Name Description
System.Double value1

Source value.

System.Double value2

Source value.

Returns
Type Description
System.Double

Max(Double, Double, Double)

Declaration
public static double Max(double a, double b, double c)
Parameters
Type Name Description
System.Double a
System.Double b
System.Double c
Returns
Type Description
System.Double

Max(Int32, Int32, Int32)

Declaration
public static int Max(int a, int b, int c)
Parameters
Type Name Description
System.Int32 a
System.Int32 b
System.Int32 c
Returns
Type Description
System.Int32

Max(Single, Single)

Returns the greater of two values.

Declaration
public static float Max(float value1, float value2)
Parameters
Type Name Description
System.Single value1

Source value.

System.Single value2

Source value.

Returns
Type Description
System.Single

Max(Single, Single, Single)

Declaration
public static float Max(float a, float b, float c)
Parameters
Type Name Description
System.Single a
System.Single b
System.Single c
Returns
Type Description
System.Single

Min(Double, Double)

Returns the lesser of two values.

Declaration
public static double Min(double value1, double value2)
Parameters
Type Name Description
System.Double value1

Source value.

System.Double value2

Source value.

Returns
Type Description
System.Double

Min(Double, Double, Double)

Declaration
public static double Min(double a, double b, double c)
Parameters
Type Name Description
System.Double a
System.Double b
System.Double c
Returns
Type Description
System.Double

Min(Single, Single)

Returns the lesser of two values.

Declaration
public static float Min(float value1, float value2)
Parameters
Type Name Description
System.Single value1

Source value.

System.Single value2

Source value.

Returns
Type Description
System.Single

Min(Single, Single, Single)

Declaration
public static float Min(float a, float b, float c)
Parameters
Type Name Description
System.Single a
System.Single b
System.Single c
Returns
Type Description
System.Single

MonotonicAcos(Single)

Declaration
public static float MonotonicAcos(float cos)
Parameters
Type Name Description
System.Single cos
Returns
Type Description
System.Single

MonotonicCosine(Single)

Calculate the monotonic cosine of a value.

Monotonic cosine is an alternative cosine encoding that is monotonic in the [-pi, pi] interval. We use this when some parameter of an onject in a planet is constrained by latitude.

The 'monotonicity' is guaranteed by subtracting the cosine value from 2 if the angle is positive. So for instance MonotonicCos(pi/2) = 2.

This only works in the above interval of course.

Declaration
public static float MonotonicCosine(float radians)
Parameters
Type Name Description
System.Single radians

The angle in radians.

Returns
Type Description
System.Single

The cosine of the angle if it is > 0, 2 - that value otherwise.

Pow2(Int32)

Returns 2^n

Declaration
public static int Pow2(int n)
Parameters
Type Name Description
System.Int32 n
Returns
Type Description
System.Int32

RoundOn2(Single)

Declaration
public static float RoundOn2(float x)
Parameters
Type Name Description
System.Single x
Returns
Type Description
System.Single

RoundToInt(Double)

Declaration
public static int RoundToInt(double x)
Parameters
Type Name Description
System.Double x
Returns
Type Description
System.Int32

RoundToInt(Single)

Declaration
public static int RoundToInt(float x)
Parameters
Type Name Description
System.Single x
Returns
Type Description
System.Int32

Saturate(Double)

Declaration
public static double Saturate(double n)
Parameters
Type Name Description
System.Double n
Returns
Type Description
System.Double

Saturate(Single)

Declaration
public static float Saturate(float n)
Parameters
Type Name Description
System.Single n
Returns
Type Description
System.Single

SCurve3(Double)

Declaration
public static double SCurve3(double t)
Parameters
Type Name Description
System.Double t
Returns
Type Description
System.Double

SCurve3(Single)

Declaration
public static float SCurve3(float t)
Parameters
Type Name Description
System.Single t
Returns
Type Description
System.Single

SCurve5(Double)

Declaration
public static double SCurve5(double t)
Parameters
Type Name Description
System.Double t
Returns
Type Description
System.Double

SCurve5(Single)

Declaration
public static float SCurve5(float t)
Parameters
Type Name Description
System.Single t
Returns
Type Description
System.Single

Smooth(Int32, Int32)

Declaration
public static int Smooth(int newValue, int lastSmooth)
Parameters
Type Name Description
System.Int32 newValue
System.Int32 lastSmooth
Returns
Type Description
System.Int32

Smooth(Single, Single)

Declaration
public static float Smooth(float newValue, float lastSmooth)
Parameters
Type Name Description
System.Single newValue
System.Single lastSmooth
Returns
Type Description
System.Single

SmoothStep(Double, Double, Double)

Interpolates between two values using a cubic equation.

Declaration
public static double SmoothStep(double value1, double value2, double amount)
Parameters
Type Name Description
System.Double value1

Source value.

System.Double value2

Source value.

System.Double amount

Weighting value.

Returns
Type Description
System.Double

SmoothStep(Single, Single, Single)

Interpolates between two values using a cubic equation.

Declaration
public static float SmoothStep(float value1, float value2, float amount)
Parameters
Type Name Description
System.Single value1

Source value.

System.Single value2

Source value.

System.Single amount

Weighting value.

Returns
Type Description
System.Single

SmoothStepStable(Double)

Interpolates between zero and one using cubic equiation, solved by de Casteljau.

Declaration
public static double SmoothStepStable(double amount)
Parameters
Type Name Description
System.Double amount

Weighting value [0..1].

Returns
Type Description
System.Double

SmoothStepStable(Single)

Interpolates between zero and one using cubic equiation, solved by de Casteljau.

Declaration
public static float SmoothStepStable(float amount)
Parameters
Type Name Description
System.Single amount

Weighting value [0..1].

Returns
Type Description
System.Single

ToDegrees(Double)

Declaration
public static double ToDegrees(double radians)
Parameters
Type Name Description
System.Double radians
Returns
Type Description
System.Double

ToDegrees(Single)

Converts radians to degrees.

Declaration
public static float ToDegrees(float radians)
Parameters
Type Name Description
System.Single radians

The angle in radians.

Returns
Type Description
System.Single

ToRadians(Double)

Converts degrees to radians.

Declaration
public static double ToRadians(double degrees)
Parameters
Type Name Description
System.Double degrees

The angle in degrees.

Returns
Type Description
System.Double

ToRadians(Single)

Converts degrees to radians.

Declaration
public static float ToRadians(float degrees)
Parameters
Type Name Description
System.Single degrees

The angle in degrees.

Returns
Type Description
System.Single

ToRadians(Vector3)

Declaration
public static Vector3 ToRadians(Vector3 v)
Parameters
Type Name Description
Vector3 v
Returns
Type Description
Vector3

WrapAngle(Single)

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

Declaration
public static float WrapAngle(float angle)
Parameters
Type Name Description
System.Single angle

The angle to reduce, in radians.

Returns
Type Description
System.Single
☀
☾
In This Article
Back to top
Generated by DocFX
☀
☾