Class MathUtil
- Namespace
- HelixToolkit.Maths
- Assembly
- HelixToolkit.Maths.dll
public static class MathUtil
- Inheritance
-
MathUtil
- Inherited Members
Fields
Pi
A value specifying the approximation of π which is 180 degrees.
public const float Pi = 3.1415927
Field Value
PiOverFour
A value specifying the approximation of π/4 which is 45 degrees.
public const float PiOverFour = 0.7853982
Field Value
PiOverTwo
A value specifying the approximation of π/2 which is 90 degrees.
public const float PiOverTwo = 1.5707964
Field Value
TwoPi
A value specifying the approximation of 2π which is 360 degrees.
public const float TwoPi = 6.2831855
Field Value
ZeroTolerance
The value for which all absolute numbers smaller than are considered equal to zero.
public const float ZeroTolerance = 1E-06
Field Value
Methods
Clamp(double, double, double)
Clamps the specified value.
public static double Clamp(double value, double min, double max)
Parameters
Returns
- double
The result of clamping a value between min and max
Clamp(int, int, int)
Clamps the specified value.
public static int Clamp(int value, int min, int max)
Parameters
Returns
- int
The result of clamping a value between min and max
Clamp(float, float, float)
Clamps the specified value.
public static float Clamp(float value, float min, float max)
Parameters
Returns
- float
The result of clamping a value between min and max
DegreesToRadians(float)
Converts degrees to radians.
public static float DegreesToRadians(float degree)
Parameters
degreefloatThe value to convert.
Returns
- float
The converted value.
DegreesToRevolutions(float)
Converts degrees to revolutions.
public static float DegreesToRevolutions(float degree)
Parameters
degreefloatThe value to convert.
Returns
- float
The converted value.
Gauss(double, double, double, double, double, double, double)
public static double Gauss(double amplitude, double x, double y, double centerX, double centerY, double sigmaX, double sigmaY)
Parameters
amplitudedoubleCurve amplitude.
xdoublePosition X.
ydoublePosition Y
centerXdoubleCenter X.
centerYdoubleCenter Y.
sigmaXdoubleCurve sigma X.
sigmaYdoubleCurve sigma Y.
Returns
- double
The result of Gaussian function.
Gauss(float, float, float, float, float, float, float)
public static float Gauss(float amplitude, float x, float y, float centerX, float centerY, float sigmaX, float sigmaY)
Parameters
amplitudefloatCurve amplitude.
xfloatPosition X.
yfloatPosition Y
centerXfloatCenter X.
centerYfloatCenter Y.
sigmaXfloatCurve sigma X.
sigmaYfloatCurve sigma Y.
Returns
- float
The result of Gaussian function.
GradiansToDegrees(float)
Converts gradians to degrees.
public static float GradiansToDegrees(float gradian)
Parameters
gradianfloatThe value to convert.
Returns
- float
The converted value.
GradiansToRadians(float)
Converts gradians to radians.
public static float GradiansToRadians(float gradian)
Parameters
gradianfloatThe value to convert.
Returns
- float
The converted value.
GradiansToRevolutions(float)
Converts gradians to revolutions.
public static float GradiansToRevolutions(float gradian)
Parameters
gradianfloatThe value to convert.
Returns
- float
The converted value.
IsOne(float)
Determines whether the specified value is close to one (1.0f).
public static bool IsOne(float a)
Parameters
afloatThe floating value.
Returns
- bool
trueif the specified value is close to one (1.0f); otherwise,false.
IsZero(float)
Determines whether the specified value is close to zero (0.0f).
public static bool IsZero(float a)
Parameters
afloatThe floating value.
Returns
- bool
trueif the specified value is close to zero (0.0f); otherwise,false.
Lerp(byte, byte, float)
Interpolates between two values using a linear function by a given amount.
public static byte Lerp(byte from, byte to, float amount)
Parameters
frombyteValue to interpolate from.
tobyteValue to interpolate to.
amountfloatInterpolation amount.
Returns
- byte
The result of linear interpolation of values based on the amount.
Remarks
See http://www.encyclopediaofmath.org/index.php/Linear_interpolation and http://fgiesen.wordpress.com/2012/08/15/linear-interpolation-past-present-and-future/
Lerp(double, double, double)
Interpolates between two values using a linear function by a given amount.
public static double Lerp(double from, double to, double amount)
Parameters
fromdoubleValue to interpolate from.
todoubleValue to interpolate to.
amountdoubleInterpolation amount.
Returns
- double
The result of linear interpolation of values based on the amount.
Remarks
See http://www.encyclopediaofmath.org/index.php/Linear_interpolation and http://fgiesen.wordpress.com/2012/08/15/linear-interpolation-past-present-and-future/
Lerp(float, float, float)
Interpolates between two values using a linear function by a given amount.
public static float Lerp(float from, float to, float amount)
Parameters
fromfloatValue to interpolate from.
tofloatValue to interpolate to.
amountfloatInterpolation amount.
Returns
- float
The result of linear interpolation of values based on the amount.
Remarks
See http://www.encyclopediaofmath.org/index.php/Linear_interpolation and http://fgiesen.wordpress.com/2012/08/15/linear-interpolation-past-present-and-future/
Mod(float, float)
Calculates the modulo of the specified value.
public static float Mod(float value, float modulo)
Parameters
Returns
- float
The result of the modulo applied to value
Mod2PI(float)
Calculates the modulo 2*PI of the specified value.
public static float Mod2PI(float value)
Parameters
valuefloatThe value.
Returns
- float
The result of the modulo applied to value
NearEqual(float, float)
Checks if a and b are almost equals, taking into account the magnitude of floating point numbers (unlike WithinEpsilon(float, float, float) method). See Remarks. See remarks.
public static bool NearEqual(float a, float b)
Parameters
Returns
- bool
trueif a almost equal to b,falseotherwise
Remarks
The code is using the technique described by Bruce Dawson in Comparing Floating point numbers 2012 edition.
RadiansToDegrees(float)
Converts radians to degrees.
public static float RadiansToDegrees(float radian)
Parameters
radianfloatThe value to convert.
Returns
- float
The converted value.
RadiansToGradians(float)
Converts radians to gradians.
public static float RadiansToGradians(float radian)
Parameters
radianfloatThe value to convert.
Returns
- float
The converted value.
RadiansToRevolutions(float)
Converts radians to revolutions.
public static float RadiansToRevolutions(float radian)
Parameters
radianfloatThe value to convert.
Returns
- float
The converted value.
RevolutionsToDegrees(float)
Converts revolutions to degrees.
public static float RevolutionsToDegrees(float revolution)
Parameters
revolutionfloatThe value to convert.
Returns
- float
The converted value.
RevolutionsToGradians(float)
Converts revolutions to gradians.
public static float RevolutionsToGradians(float revolution)
Parameters
revolutionfloatThe value to convert.
Returns
- float
The converted value.
RevolutionsToRadians(float)
Converts revolutions to radians.
public static float RevolutionsToRadians(float revolution)
Parameters
revolutionfloatThe value to convert.
Returns
- float
The converted value.
SmoothStep(float)
Performs smooth (cubic Hermite) interpolation between 0 and 1.
public static float SmoothStep(float amount)
Parameters
amountfloatValue between 0 and 1 indicating interpolation amount.
Returns
Remarks
SmootherStep(float)
Performs a smooth(er) interpolation between 0 and 1 with 1st and 2nd order derivatives of zero at endpoints.
public static float SmootherStep(float amount)
Parameters
amountfloatValue between 0 and 1 indicating interpolation amount.
Returns
Remarks
WithinEpsilon(float, float, float)
Checks if a - b are almost equals within a float epsilon.
public static bool WithinEpsilon(float a, float b, float epsilon)
Parameters
Returns
- bool
trueif a almost equal to b within a float epsilon,falseotherwise
Wrap(int, int, int)
Wraps the specified value into a range [min, max]
public static int Wrap(int value, int min, int max)
Parameters
Returns
- int
Result of the wrapping.
Exceptions
- ArgumentException
Is thrown when
minis greater thanmax.
Wrap(float, float, float)
Wraps the specified value into a range [min, max]
public static float Wrap(float value, float min, float max)
Parameters
Returns
- float
Result of the wrapping.
Exceptions
- ArgumentException
Is thrown when
minis greater thanmax.