class MathX

in global :: Sandbox

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();`


public static float DegreeToRadian( float deg )

Convert degrees to radians. 180 degrees is (roughly 3.14) radians, etc.

  • deg A value in degrees to convert.
  • Returns The given value converted to radians.

public static float RadianToDegree( float rad )

Convert radians to degrees. 180 degrees is (roughly 3.14) radians, etc.

  • rad A value in radians to convert.
  • Returns The given value converted to degrees.

public static float GradiansToDegrees( float grad )

Convert gradians to degrees. 100 gradian is 90 degrees, 200 gradian is 180 degrees, etc.

  • grad A value in gradians to convert.
  • Returns The given value converted to degrees.

public static float GradiansToRadians( float grad )

Convert gradians to radians. 200 gradian is (roughly 3.14) radians, etc.

  • grad A value in gradians to convert.
  • Returns The given value converted to radians.

public static float MeterToInch( float meters )

Convert meters to inches.

public static float InchToMeter( float inches )

Convert inches to meters.

public static float InchToMillimeter( float inches )

Convert inches to millimeters.

public static float MillimeterToInch( float millimeters )

Convert millimeters to inches.

public static float SnapToGrid( float f, float gridSize )

Snap number to grid

public static int SnapToGrid( int f, int gridSize )

Snap number to grid

public static int FloorToInt( float f )

Remove the fractional part and return the float as an integer.

public static float Floor( float f )

Remove the fractional part of given floating point number

public static int CeilToInt( float f )

Rounds up given float to next integer value.

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.

  • v The value to clamp.
  • min Minimum return value.
  • max Maximum return value.
  • Returns The clamped float.

public static float Lerp( float from, float to, float frac, bool 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 .
  • Returns The result of linear interpolation.

public static float LerpTo( float from, float to, float frac, bool clamp = True )

🤡 Doc inheritance is not yet supported.

No summary.

public static float[] LerpTo( float[] from, float[] to, float delta, bool clamp = True )

Performs multiple linear interpolations at the same time.

public static float LerpDegrees( float from, float to, float frac, bool clamp = True )

Linearly interpolates between two angles in degrees, taking the shortest arc.

public static float LerpDegreesTo( float from, float to, float frac, bool clamp = True )

🤡 Doc inheritance is not yet supported.

No summary.

public static float LerpRadians( float from, float to, float frac, bool clamp = True )

Linearly interpolates between two angles in radians, taking the shortest arc.

public static float LerpRadiansTo( float from, float to, float frac, bool clamp = True )

🤡 Doc inheritance is not yet supported.

No summary.

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.

  • 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.
  • Returns The resulting fraction.

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.

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.

public static float UnsignedMod( float a, float b )

Does what you expected to happen when you did "a % b"

public static float NormalizeDegrees( float degree )

Convert angle to between 0 - 360

public static float DeltaDegrees( float from, float to )

Difference between two angles in degrees. Will always be between -180 and +180.

public static float DeltaRadians( float from, float to )

Difference between two angles in radians. Will always be between -PI and +PI.

public static float Remap( float value, float oldLow, float oldHigh, float newLow = 0, float newHigh = 1 )

Remap a float value from a one range to another. Clamps value between newLow and newHigh.

public static float Remap( float value, float oldLow, float oldHigh, float newLow, float newHigh, bool clamp )

Remap a float value from a one range to another

public static double Remap( double value, double oldLow, double oldHigh, double newLow, double newHigh, bool clamp )

Remap a double value from a one range to another

public static int Remap( int value, int oldLow, int oldHigh, int newLow, int newHigh )

Remap an integer value from a one range to another

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?

  • radius The radius of the sphere
  • fieldOfView The field of view in degrees
  • Returns The optimal distance from the center of the sphere

public static float SmoothDamp( float current, float target, ref float velocity, float smoothTime, float deltaTime )

Smoothly move towards the target

public static float SpringDamp( float current, float target, ref float velocity, float deltaTime, float frequency = 2, float damping = 0.5 )

Smoothly move towards the target using a spring-like motion

public Type GetType( )

😔 No documentation found.

public string ToString( )

😔 No documentation found.

public bool Equals( object obj )

😔 No documentation found.

public int GetHashCode( )

😔 No documentation found.