MathX
public static abstract sealed class MathX 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();`
Methods
static this Single DegreeToRadian(Single deg) Convert degrees to radians. 180 degrees is PI (roughly 3.14) radians, etc.
deg — A value in degrees to convert. static this Single RadianToDegree(Single rad) Convert radians to degrees. 180 degrees is PI (roughly 3.14) radians, etc.
rad — A value in radians to convert. static this Single GradiansToDegrees(Single grad) Convert gradians to degrees. 100 gradian is 90 degrees, 200 gradian is 180 degrees, etc.
grad — A value in gradians to convert. static this Single GradiansToRadians(Single grad) Convert gradians to radians. 200 gradian is PI (roughly 3.14) radians, etc.
grad — A value in gradians to convert. static this Single MeterToInch(Single meters) Convert meters to inches.
static this Single InchToMeter(Single inches) Convert inches to meters.
static this Single InchToMillimeter(Single inches) Convert inches to millimeters.
static this Single MillimeterToInch(Single millimeters) Convert millimeters to inches.
static this Single SnapToGrid(Single f, Single gridSize) Snap number to grid
static this Int32 SnapToGrid(Int32 f, Int32 gridSize) Snap number to grid
static this Int32 FloorToInt(Single f) Remove the fractional part and return the float as an integer.
static this Single Floor(Single f) Remove the fractional part of given floating point number
static this Int32 CeilToInt(Single f) Rounds up given float to next integer value.
static this Single Clamp(Single v, Single min, Single max) Clamp a float between 2 given extremes. If given value is lower than the given minimum value, returns the minimum value, etc.
v — The value to clamp. min — Minimum return value. max — Maximum return value. static Single Lerp(Single from, Single to, Single frac, Boolean clamp = True) Performs linear interpolation on floating point numbers.
from — The "starting value" of the interpolation. to — The "final value" of the interpolation. frac — The fraction in range of 0 (will return value of ) to 1 (will return value of ). clamp — Whether to clamp the fraction between 0 and 1, and therefore the output value between and . static Double Lerp(Double from, Double to, Double frac, Boolean clamp = True) Performs linear interpolation on floating point numbers.
from — The "starting value" of the interpolation. to — The "final value" of the interpolation. frac — The fraction in range of 0 (will return value of ) to 1 (will return value of ). clamp — Whether to clamp the fraction between 0 and 1, and therefore the output value between and . static this Single LerpTo(Single from, Single to, Single frac, Boolean clamp = True) static this Single[] LerpTo(Single[] from, Single[] to, Single delta, Boolean clamp = True) Performs multiple linear interpolations at the same time.
static Single LerpDegrees(Single from, Single to, Single frac, Boolean clamp = True) Linearly interpolates between two angles in degrees, taking the shortest arc.
static this Single LerpDegreesTo(Single from, Single to, Single frac, Boolean clamp = True) static Single LerpRadians(Single from, Single to, Single frac, Boolean clamp = True) Linearly interpolates between two angles in radians, taking the shortest arc.
static this Single LerpRadiansTo(Single from, Single to, Single frac, Boolean clamp = True) static this Single LerpInverse(Single value, Single from, Single to, Boolean clamp = True) Performs inverse of a linear interpolation, that is, the return value is the fraction of a linear interpolation.
value — The value relative to and . from — The "starting value" of the interpolation. If is at this value or less, the function will return 0 or less. to — The "final value" of the interpolation. If is at this value or greater, the function will return 1 or greater. clamp — Whether the return value is allowed to exceed range of 0 - 1. static this Single Approach(Single f, Single target, Single delta) Adds or subtracts given amount based on whether the input is smaller of bigger than the target.
static this Boolean AlmostEqual(Single value, Single b, Single within = 0.0001) Returns true if given value is close to given value within given tolerance.
static this Single UnsignedMod(Single a, Single b) Does what you expected to happen when you did "a % b"
static this Single NormalizeDegrees(Single degree) Convert angle to between 0 - 360
static Single DeltaDegrees(Single from, Single to) Difference between two angles in degrees. Will always be between -180 and +180.
static Single DeltaRadians(Single from, Single to) Difference between two angles in radians. Will always be between -PI and +PI.
static this Single Remap(Single value, Single oldLow, Single oldHigh, Single newLow = 0, Single newHigh = 1) Remap a float value from a one range to another. Clamps value between newLow and newHigh.
static this Double Remap(Double value, Double oldLow, Double oldHigh, Double newLow = 0, Double newHigh = 1) Remap a double value from one range to another. Clamps value between newLow and newHigh.
static this Single Remap(Single value, Single oldLow, Single oldHigh, Single newLow, Single newHigh, Boolean clamp) Remap a float value from a one range to another
static this Double Remap(Double value, Double oldLow, Double oldHigh, Double newLow, Double newHigh, Boolean clamp) Remap a double value from a one range to another
static this Int32 Remap(Int32 value, Int32 oldLow, Int32 oldHigh, Int32 newLow, Int32 newHigh) Remap an integer value from a one range to another
static Single SphereCameraDistance(Single radius, Single fieldOfView) Given a sphere and a field of view, how far from the camera should we be to fully see the sphere?
radius — The radius of the sphere fieldOfView — The field of view in degrees static Single ExponentialDecay(Single current, Single target, Single halflife, Single deltaTime) Smoothly approach the target value using exponential decay. Cheaper than SmoothDamp but doesn't track velocity for momentum. Good for non-physical smoothing.
current — Current value target — Target value to approach halflife — Time for the difference to reduce by 50% deltaTime — Time step static Single SmoothDamp(Single current, Single target, Single velocity, Single smoothTime, Single deltaTime) Smoothly move towards the target
static Single SpringDamp(Single current, Single target, Single velocity, Single deltaTime, Single frequency = 2, Single damping = 0.5) Smoothly move towards the target using a spring-like motion