MathXclass
A class to add functionality to the math library that System.Math and System.MathF don't provide. A lot of these methods are also extensions, so you can use for example `int i = 1.0f.FloorToInt();`
Methods38
Showing 38 methods
public static bool AlmostEqual(float value, float b, float within = 0.0001)
Returns true if given value is close to given value within given tolerance.
| Parameter | Type | Description |
|---|---|---|
| value | float | — |
| b | float | — |
| within = 0.0001 | float | — |
bool—public static float Approach(float f, float target, float delta)
Adds or subtracts given amount based on whether the input is smaller of bigger than the target.
| Parameter | Type | Description |
|---|---|---|
| f | float | — |
| target | float | — |
| delta | float | — |
float—public static int CeilToInt(float f)
Rounds up given float to next integer value.
| Parameter | Type | Description |
|---|---|---|
| f | float | — |
int—public static float Clamp(float v, float min, float max)
Clamp a float between 2 given extremes. If given value is lower than the given minimum value, returns the minimum value, etc.
| Parameter | Type | Description |
|---|---|---|
| v | float | The value to clamp. |
| min | float | Minimum return value. |
| max | float | Maximum return value. |
floatThe clamped float.public static float DegreeToRadian(float deg)
Convert degrees to radians. 180 degrees is `System.Math.PI` (roughly 3.14) radians, etc.
| Parameter | Type | Description |
|---|---|---|
| deg | float | A value in degrees to convert. |
floatThe given value converted to radians.public static float DeltaDegrees(float from, float to)
Difference between two angles in degrees. Will always be between -180 and +180.
| Parameter | Type | Description |
|---|---|---|
| from | float | — |
| to | float | — |
float—public static float DeltaRadians(float from, float to)
Difference between two angles in radians. Will always be between -PI and +PI.
| Parameter | Type | Description |
|---|---|---|
| from | float | — |
| to | float | — |
float—public static float ExponentialDecay(float current, float target, float halflife, float deltaTime)
Smoothly approach the target value using exponential decay. Cheaper than SmoothDamp but doesn't track velocity for momentum. Good for non-physical smoothing.
| Parameter | Type | Description |
|---|---|---|
| current | float | Current value |
| target | float | Target value to approach |
| halflife | float | Time for the difference to reduce by 50% |
| deltaTime | float | Time step |
float—public static float Floor(float f)
Remove the fractional part of given floating point number
| Parameter | Type | Description |
|---|---|---|
| f | float | — |
float—public static int FloorToInt(float f)
Remove the fractional part and return the float as an integer.
| Parameter | Type | Description |
|---|---|---|
| f | float | — |
int—public static float GradiansToDegrees(float grad)
Convert gradians to degrees. 100 gradian is 90 degrees, 200 gradian is 180 degrees, etc.
| Parameter | Type | Description |
|---|---|---|
| grad | float | A value in gradians to convert. |
floatThe given value converted to degrees.public static float GradiansToRadians(float grad)
Convert gradians to radians. 200 gradian is `System.Math.PI` (roughly 3.14) radians, etc.
| Parameter | Type | Description |
|---|---|---|
| grad | float | A value in gradians to convert. |
floatThe given value converted to radians.public static float InchToMeter(float inches)
Convert inches to meters.
| Parameter | Type | Description |
|---|---|---|
| inches | float | — |
float—public static float InchToMillimeter(float inches)
Convert inches to millimeters.
| Parameter | Type | Description |
|---|---|---|
| inches | float | — |
float—public static float LerpDegrees(float from, float to, float frac, bool clamp = True)
Linearly interpolates between two angles in degrees, taking the shortest arc.
| Parameter | Type | Description |
|---|---|---|
| from | float | — |
| to | float | — |
| frac | float | — |
| clamp = True | bool | — |
float—public static float LerpDegreesTo(float from, float to, float frac, bool clamp = True)
| Parameter | Type | Description |
|---|---|---|
| from | float | — |
| to | float | — |
| frac | float | — |
| clamp = True | bool | — |
float—public static float LerpInverse(float value, float from, float to, bool clamp = True)
Performs inverse of a linear interpolation, that is, the return value is the fraction of a linear interpolation.
| Parameter | Type | Description |
|---|---|---|
| value | float | The value relative to `from` and `to`. |
| from | float | The "starting value" of the interpolation. If `value` is at this value or less, the function will return 0 or less. |
| to | float | The "final value" of the interpolation. If `value` is at this value or greater, the function will return 1 or greater. |
| clamp = True | bool | Whether the return value is allowed to exceed range of 0 - 1. |
floatThe resulting fraction.public static float LerpRadians(float from, float to, float frac, bool clamp = True)
Linearly interpolates between two angles in radians, taking the shortest arc.
| Parameter | Type | Description |
|---|---|---|
| from | float | — |
| to | float | — |
| frac | float | — |
| clamp = True | bool | — |
float—public static float LerpRadiansTo(float from, float to, float frac, bool clamp = True)
| Parameter | Type | Description |
|---|---|---|
| from | float | — |
| to | float | — |
| frac | float | — |
| clamp = True | bool | — |
float—public static float MeterToInch(float meters)
Convert meters to inches.
| Parameter | Type | Description |
|---|---|---|
| meters | float | — |
float—public static float MillimeterToInch(float millimeters)
Convert millimeters to inches.
| Parameter | Type | Description |
|---|---|---|
| millimeters | float | — |
float—public static float NormalizeDegrees(float degree)
Convert angle to between 0 - 360
| Parameter | Type | Description |
|---|---|---|
| degree | float | — |
float—public static float RadianToDegree(float rad)
Convert radians to degrees. 180 degrees is `System.Math.PI` (roughly 3.14) radians, etc.
| Parameter | Type | Description |
|---|---|---|
| rad | float | A value in radians to convert. |
floatThe given value converted to degrees.public static float SmoothDamp(float current, float target, float velocity, float smoothTime, float deltaTime)
Smoothly move towards the target
| Parameter | Type | Description |
|---|---|---|
| current | float | — |
| target | float | — |
| velocity | float | — |
| smoothTime | float | — |
| deltaTime | float | — |
float—public static float SphereCameraDistance(float radius, float fieldOfView)
Given a sphere and a field of view, how far from the camera should we be to fully see the sphere?
| Parameter | Type | Description |
|---|---|---|
| radius | float | The radius of the sphere |
| fieldOfView | float | The field of view in degrees |
floatThe optimal distance from the center of the spherepublic static float SpringDamp(float current, float target, float velocity, float deltaTime, float frequency = 2, float damping = 0.5)
Smoothly move towards the target using a spring-like motion
| Parameter | Type | Description |
|---|---|---|
| current | float | — |
| target | float | — |
| velocity | float | — |
| deltaTime | float | — |
| frequency = 2 | float | — |
| damping = 0.5 | float | — |
float—public static float UnsignedMod(float a, float b)
Does what you expected to happen when you did "a % b"
| Parameter | Type | Description |
|---|---|---|
| a | float | — |
| b | float | — |
float—No results match this filter.