Class MathUtility
Provides static helpers methods for mathematical functions not found in the .NET
Inheritance
Namespace: X10D.Math
Assembly: X10D.dll
Syntax
public static class MathUtility : object
Methods
| Improve this Doc View SourceBias(Double, Double)
Applies a simple bias function to value.
Declaration
public static double Bias(double value, double bias)
Parameters
Type | Name | Description |
---|---|---|
System.Double | value | The value to which the bias function will be applied. |
System.Double | bias | The bias value. Valid values range from 0-1. |
Returns
Type | Description |
---|---|
System.Double | The biased result. |
Remarks
If bias
is less than 0.5, value
will be shifted downward; otherwise, upward.
Bias(Single, Single)
Applies a simple bias function to value.
Declaration
public static float Bias(float value, float bias)
Parameters
Type | Name | Description |
---|---|---|
System.Single | value | The value to which the bias function will be applied. |
System.Single | bias | The bias value. Valid values range from 0-1. |
Returns
Type | Description |
---|---|
System.Single | The biased result. |
Remarks
If bias
is less than 0.5, value
will be shifted downward; otherwise, upward.
ExponentialDecay(Double, Double, Double)
Calculates exponential decay for a value.
Declaration
public static double ExponentialDecay(double value, double alpha, double decay)
Parameters
Type | Name | Description |
---|---|---|
System.Double | value | The value to decay. |
System.Double | alpha | A factor by which to scale the decay. |
System.Double | decay | The decay amount. |
Returns
Type | Description |
---|---|
System.Double | The exponentially decayed value. |
ExponentialDecay(Single, Single, Single)
Calculates exponential decay for a value.
Declaration
public static float ExponentialDecay(float value, float alpha, float decay)
Parameters
Type | Name | Description |
---|---|---|
System.Single | value | The value to decay. |
System.Single | alpha | A factor by which to scale the decay. |
System.Single | decay | The decay amount. |
Returns
Type | Description |
---|---|
System.Single | The exponentially decayed value. |
GammaToLinear(Double)
Converts a gamma-encoded value to a linear value using a gamma value of 2.2
.
Declaration
public static double GammaToLinear(double value)
Parameters
Type | Name | Description |
---|---|---|
System.Double | value | The gamma-encoded value to convert. Expected range is [0, 1]. |
Returns
Type | Description |
---|---|
System.Double | The linear value. |
GammaToLinear(Double, Double)
Converts a gamma-encoded value to a linear value using the specified gamma value.
Declaration
public static double GammaToLinear(double value, double gamma)
Parameters
Type | Name | Description |
---|---|---|
System.Double | value | The gamma-encoded value to convert. Expected range is [0, 1]. |
System.Double | gamma | The gamma value to use for decoding. |
Returns
Type | Description |
---|---|
System.Double | The linear value. |
GammaToLinear(Single)
Converts a gamma-encoded value to a linear value using a gamma value of 2.2
.
Declaration
public static float GammaToLinear(float value)
Parameters
Type | Name | Description |
---|---|---|
System.Single | value | The gamma-encoded value to convert. Expected range is [0, 1]. |
Returns
Type | Description |
---|---|
System.Single | The linear value. |
GammaToLinear(Single, Single)
Converts a gamma-encoded value to a linear value using the specified gamma value.
Declaration
public static float GammaToLinear(float value, float gamma)
Parameters
Type | Name | Description |
---|---|---|
System.Single | value | The gamma-encoded value to convert. Expected range is [0, 1]. |
System.Single | gamma | The gamma value to use for decoding. |
Returns
Type | Description |
---|---|
System.Single | The linear value. |
InverseLerp(Double, Double, Double)
Returns the linear interpolation inverse of a value, such that it determines where a value lies between two other values.
Declaration
public static double InverseLerp(double alpha, double start, double end)
Parameters
Type | Name | Description |
---|---|---|
System.Double | alpha | The value whose lerp inverse is to be found. |
System.Double | start | The start of the range. |
System.Double | end | The end of the range. |
Returns
Type | Description |
---|---|
System.Double | A value determined by |
InverseLerp(Single, Single, Single)
Returns the linear interpolation inverse of a value, such that it determines where a value lies between two other values.
Declaration
public static float InverseLerp(float alpha, float start, float end)
Parameters
Type | Name | Description |
---|---|---|
System.Single | alpha | The value whose lerp inverse is to be found. |
System.Single | start | The start of the range. |
System.Single | end | The end of the range. |
Returns
Type | Description |
---|---|
System.Single | A value determined by |
Lerp(Double, Double, Double)
Linearly interpolates from one value to a target using a specified alpha.
Declaration
public static double Lerp(double value, double target, double alpha)
Parameters
Type | Name | Description |
---|---|---|
System.Double | value | The interpolation source. |
System.Double | target | The interpolation target. |
System.Double | alpha | The interpolation alpha. |
Returns
Type | Description |
---|---|
System.Double | The interpolation result as determined by |
Lerp(Single, Single, Single)
Linearly interpolates from one value to a target using a specified alpha.
Declaration
public static float Lerp(float value, float target, float alpha)
Parameters
Type | Name | Description |
---|---|---|
System.Single | value | The interpolation source. |
System.Single | target | The interpolation target. |
System.Single | alpha | The interpolation alpha. |
Returns
Type | Description |
---|---|
System.Single | The interpolation result as determined by |
LinearToGamma(Double)
Converts a linear value to a gamma-encoded value using a gamma value of 2.2
.
Declaration
public static double LinearToGamma(double value)
Parameters
Type | Name | Description |
---|---|---|
System.Double | value | The linear value to convert. Expected range is [0, 1]. |
Returns
Type | Description |
---|---|
System.Double | The gamma-encoded value. |
LinearToGamma(Double, Double)
Converts a linear value to a gamma-encoded value using the specified gamma value.
Declaration
public static double LinearToGamma(double value, double gamma)
Parameters
Type | Name | Description |
---|---|---|
System.Double | value | The linear value to convert. Expected range is [0, 1]. |
System.Double | gamma | The gamma value to use for encoding. |
Returns
Type | Description |
---|---|
System.Double | The gamma-encoded value. |
LinearToGamma(Single)
Converts a linear value to a gamma-encoded value using a gamma value of 2.2
.
Declaration
public static float LinearToGamma(float value)
Parameters
Type | Name | Description |
---|---|---|
System.Single | value | The linear value to convert. Expected range is [0, 1]. |
Returns
Type | Description |
---|---|
System.Single | The gamma-encoded value. |
LinearToGamma(Single, Single)
Converts a linear value to a gamma-encoded value using the specified gamma value.
Declaration
public static float LinearToGamma(float value, float gamma)
Parameters
Type | Name | Description |
---|---|---|
System.Single | value | The linear value to convert. Expected range is [0, 1]. |
System.Single | gamma | The gamma value to use for encoding. |
Returns
Type | Description |
---|---|
System.Single | The gamma-encoded value. |
Pulse(Double, Double, Double)
Returns the pulse wave for a given value.
Declaration
public static double Pulse(double value, double lowerBound, double upperBound)
Parameters
Type | Name | Description |
---|---|---|
System.Double | value | The value to calculate. |
System.Double | lowerBound | The inclusive lower bound of the pulse. |
System.Double | upperBound | The inclusive upper bound of the pulse. |
Returns
Type | Description |
---|---|
System.Double | 1 if |
Pulse(Single, Single, Single)
Returns the pulse wave for a given value.
Declaration
public static float Pulse(float value, float lowerBound, float upperBound)
Parameters
Type | Name | Description |
---|---|---|
System.Single | value | The value to calculate. |
System.Single | lowerBound | The inclusive lower bound of the pulse. |
System.Single | upperBound | The inclusive upper bound of the pulse. |
Returns
Type | Description |
---|---|
System.Single | 1 if |
Sawtooth(Double)
Returns the incremental sawtooth wave of a given value.
Declaration
public static double Sawtooth(double value)
Parameters
Type | Name | Description |
---|---|---|
System.Double | value | The value to calculate. |
Returns
Type | Description |
---|---|
System.Double | The sawtooth wave of the given value. |
Sawtooth(Single)
Returns the incremental sawtooth wave of a given value.
Declaration
public static float Sawtooth(float value)
Parameters
Type | Name | Description |
---|---|---|
System.Single | value | The value to calculate. |
Returns
Type | Description |
---|---|
System.Single | The sawtooth wave of the given value. |
ScaleRange(Double, Double, Double, Double, Double)
Converts a value from being a percentage of one range, to being the same percentage in a new range.
Declaration
public static double ScaleRange(double value, double oldMin, double oldMax, double newMin, double newMax)
Parameters
Type | Name | Description |
---|---|---|
System.Double | value | The value to convert. |
System.Double | oldMin | The old minimum value. |
System.Double | oldMax | The old maximum value. |
System.Double | newMin | The new minimum value. |
System.Double | newMax | The new maximum value. |
Returns
Type | Description |
---|---|
System.Double | The scaled value. |
ScaleRange(Single, Single, Single, Single, Single)
Converts a value from being a percentage of one range, to being the same percentage in a new range.
Declaration
public static float ScaleRange(float value, float oldMin, float oldMax, float newMin, float newMax)
Parameters
Type | Name | Description |
---|---|---|
System.Single | value | The value to convert. |
System.Single | oldMin | The old minimum value. |
System.Single | oldMax | The old maximum value. |
System.Single | newMin | The new minimum value. |
System.Single | newMax | The new maximum value. |
Returns
Type | Description |
---|---|
System.Single | The scaled value. |
Sigmoid(Double)
Calculates the sigmoid function for the given input value.
Declaration
public static double Sigmoid(double value)
Parameters
Type | Name | Description |
---|---|---|
System.Double | value | The input value for which to calculate the sigmoid function. |
Returns
Type | Description |
---|---|
System.Double | The result of applying the sigmoid function to the input value. |
Remarks
The sigmoid function is a commonly used activation function in artificial neural networks and logistic regression. It maps any real-valued number to a value between 0 and 1.
Sigmoid(Single)
Calculates the sigmoid function for the given input value.
Declaration
public static float Sigmoid(float value)
Parameters
Type | Name | Description |
---|---|---|
System.Single | value | The input value for which to calculate the sigmoid function. |
Returns
Type | Description |
---|---|
System.Single | The result of applying the sigmoid function to the input value. |
Remarks
The sigmoid function is a commonly used activation function in artificial neural networks and logistic regression. It maps any real-valued number to a value between 0 and 1.
SmoothStep(Double, Double, Double)
Performs smooth Hermite interpolation from one value to a target using a specified alpha.
Declaration
public static double SmoothStep(double value, double target, double alpha)
Parameters
Type | Name | Description |
---|---|---|
System.Double | value | The interpolation source. |
System.Double | target | The interpolation target. |
System.Double | alpha | The interpolation alpha. |
Returns
Type | Description |
---|---|
System.Double | The interpolation result. |
SmoothStep(Single, Single, Single)
Performs smooth Hermite interpolation from one value to a target using a specified alpha.
Declaration
public static float SmoothStep(float value, float target, float alpha)
Parameters
Type | Name | Description |
---|---|---|
System.Single | value | The interpolation source. |
System.Single | target | The interpolation target. |
System.Single | alpha | The interpolation alpha. |
Returns
Type | Description |
---|---|
System.Single | The interpolation result. |