Table of Contents

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

float

PiOverFour

A value specifying the approximation of π/4 which is 45 degrees.

public const float PiOverFour = 0.7853982

Field Value

float

PiOverTwo

A value specifying the approximation of π/2 which is 90 degrees.

public const float PiOverTwo = 1.5707964

Field Value

float

TwoPi

A value specifying the approximation of 2π which is 360 degrees.

public const float TwoPi = 6.2831855

Field Value

float

ZeroTolerance

The value for which all absolute numbers smaller than are considered equal to zero.

public const float ZeroTolerance = 1E-06

Field Value

float

Methods

Clamp(double, double, double)

Clamps the specified value.

public static double Clamp(double value, double min, double max)

Parameters

value double

The value.

min double

The min.

max double

The max.

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

value int

The value.

min int

The min.

max int

The max.

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

value float

The value.

min float

The min.

max float

The max.

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

degree float

The value to convert.

Returns

float

The converted value.

DegreesToRevolutions(float)

Converts degrees to revolutions.

public static float DegreesToRevolutions(float degree)

Parameters

degree float

The 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

amplitude double

Curve amplitude.

x double

Position X.

y double

Position Y

centerX double

Center X.

centerY double

Center Y.

sigmaX double

Curve sigma X.

sigmaY double

Curve 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

amplitude float

Curve amplitude.

x float

Position X.

y float

Position Y

centerX float

Center X.

centerY float

Center Y.

sigmaX float

Curve sigma X.

sigmaY float

Curve sigma Y.

Returns

float

The result of Gaussian function.

GradiansToDegrees(float)

Converts gradians to degrees.

public static float GradiansToDegrees(float gradian)

Parameters

gradian float

The value to convert.

Returns

float

The converted value.

GradiansToRadians(float)

Converts gradians to radians.

public static float GradiansToRadians(float gradian)

Parameters

gradian float

The value to convert.

Returns

float

The converted value.

GradiansToRevolutions(float)

Converts gradians to revolutions.

public static float GradiansToRevolutions(float gradian)

Parameters

gradian float

The 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

a float

The floating value.

Returns

bool

true if 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

a float

The floating value.

Returns

bool

true if 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

from byte

Value to interpolate from.

to byte

Value to interpolate to.

amount float

Interpolation amount.

Returns

byte

The result of linear interpolation of values based on the amount.

Remarks

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

from double

Value to interpolate from.

to double

Value to interpolate to.

amount double

Interpolation amount.

Returns

double

The result of linear interpolation of values based on the amount.

Remarks

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

from float

Value to interpolate from.

to float

Value to interpolate to.

amount float

Interpolation amount.

Returns

float

The result of linear interpolation of values based on the amount.

Remarks

Mod(float, float)

Calculates the modulo of the specified value.

public static float Mod(float value, float modulo)

Parameters

value float

The value.

modulo float

The modulo.

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

value float

The 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

a float

The left value to compare.

b float

The right value to compare.

Returns

bool

true if a almost equal to b, false otherwise

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

radian float

The value to convert.

Returns

float

The converted value.

RadiansToGradians(float)

Converts radians to gradians.

public static float RadiansToGradians(float radian)

Parameters

radian float

The value to convert.

Returns

float

The converted value.

RadiansToRevolutions(float)

Converts radians to revolutions.

public static float RadiansToRevolutions(float radian)

Parameters

radian float

The value to convert.

Returns

float

The converted value.

RevolutionsToDegrees(float)

Converts revolutions to degrees.

public static float RevolutionsToDegrees(float revolution)

Parameters

revolution float

The value to convert.

Returns

float

The converted value.

RevolutionsToGradians(float)

Converts revolutions to gradians.

public static float RevolutionsToGradians(float revolution)

Parameters

revolution float

The value to convert.

Returns

float

The converted value.

RevolutionsToRadians(float)

Converts revolutions to radians.

public static float RevolutionsToRadians(float revolution)

Parameters

revolution float

The 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

amount float

Value between 0 and 1 indicating interpolation amount.

Returns

float

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

amount float

Value between 0 and 1 indicating interpolation amount.

Returns

float

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

a float

The left value to compare.

b float

The right value to compare.

epsilon float

Epsilon value

Returns

bool

true if a almost equal to b within a float epsilon, false otherwise

Wrap(int, int, int)

Wraps the specified value into a range [min, max]

public static int Wrap(int value, int min, int max)

Parameters

value int

The value to wrap.

min int

The min.

max int

The max.

Returns

int

Result of the wrapping.

Exceptions

ArgumentException

Is thrown when min is greater than max.

Wrap(float, float, float)

Wraps the specified value into a range [min, max]

public static float Wrap(float value, float min, float max)

Parameters

value float

The value.

min float

The min.

max float

The max.

Returns

float

Result of the wrapping.

Exceptions

ArgumentException

Is thrown when min is greater than max.