Mathf

csharp
public static class Mathf

Namespace NodeWorld.Flux.

Math on floats, with the names of Unity's Mathf, computed inside the world's module.

Constants

PI

csharp
public const float PI = 3.14159274f

Pi as a float (3.14159274).

Infinity

csharp
public const float Infinity = float.PositiveInfinity

Positive infinity.

NegativeInfinity

csharp
public const float NegativeInfinity = float.NegativeInfinity

Negative infinity.

Deg2Rad

csharp
public const float Deg2Rad = PI / 180f

Multiply degrees by it to get radians.

Rad2Deg

csharp
public const float Rad2Deg = 180f / PI

Multiply radians by it to get degrees.

Epsilon

csharp
public const float Epsilon = float.Epsilon

The smallest positive float (denormal), as in Unity on platforms that keep denormals.

Methods

Sin

csharp
public static float Sin(float f)

Sine of an angle in radians.

Cos

csharp
public static float Cos(float f)

Cosine of an angle in radians.

Tan

csharp
public static float Tan(float f)

Tangent of an angle in radians.

Asin

csharp
public static float Asin(float f)

Arc sine, in radians.

Acos

csharp
public static float Acos(float f)

Arc cosine, in radians.

Atan

csharp
public static float Atan(float f)

Arc tangent, in radians.

Atan2

csharp
public static float Atan2(float y, float x)

The angle in radians of the point (x, y) from the x axis, -PI to PI.

Sqrt

csharp
public static float Sqrt(float f)

Square root.

Abs

csharp
public static float Abs(float f)

Absolute value.

csharp
public static int Abs(int value)

Absolute value.

Pow

csharp
public static float Pow(float f, float p)

f to the power p.

Exp

csharp
public static float Exp(float power)

e to the power power.

Log

csharp
public static float Log(float f, float p)

Logarithm of f in base p.

csharp
public static float Log(float f)

Natural logarithm (base e).

Log10

csharp
public static float Log10(float f)

Logarithm in base 10.

Floor

csharp
public static float Floor(float f)

The largest integer at or below f.

Ceil

csharp
public static float Ceil(float f)

The smallest integer at or above f.

Round

csharp
public static float Round(float f)

Nearest integer; halfway values go to the even one.

FloorToInt

csharp
public static int FloorToInt(float f)

Floor, as an int.

CeilToInt

csharp
public static int CeilToInt(float f)

Ceil, as an int.

RoundToInt

csharp
public static int RoundToInt(float f)

Round, as an int: halfway values go to the even one.

Sign

csharp
public static float Sign(float f)

1 for zero and positive values, -1 for negative ones.

Min

csharp
public static float Min(float a, float b)

The smaller of two values.

csharp
public static int Min(int a, int b)

The smaller of two values.

csharp
public static float Min(params float[] values)

The smallest of the values (0 for none).

Max

csharp
public static float Max(float a, float b)

The larger of two values.

csharp
public static int Max(int a, int b)

The larger of two values.

csharp
public static float Max(params float[] values)

The largest of the values (0 for none).

Clamp

csharp
public static float Clamp(float value, float min, float max)

value kept between min and max.

csharp
public static int Clamp(int value, int min, int max)

value kept between min and max.

Clamp01

csharp
public static float Clamp01(float value)

value kept between 0 and 1.

Lerp

csharp
public static float Lerp(float a, float b, float t)

From a (t = 0) to b (t = 1); t is kept between 0 and 1.

LerpUnclamped

csharp
public static float LerpUnclamped(float a, float b, float t)

From a (t = 0) to b (t = 1); t is not limited.

InverseLerp

csharp
public static float InverseLerp(float a, float b, float value)

Where value stands between a (0) and b (1), kept between 0 and 1; 0 when a equals b.

LerpAngle

csharp
public static float LerpAngle(float a, float b, float t)

From angle a to angle b, in degrees, the short way round; t is kept between 0 and 1.

MoveTowards

csharp
public static float MoveTowards(float current, float target, float maxDelta)

current moved towards target by maxDelta at most.

MoveTowardsAngle

csharp
public static float MoveTowardsAngle(float current, float target, float maxDelta)

Angle current moved towards angle target by maxDelta degrees at most, the short way round.

SmoothStep

csharp
public static float SmoothStep(float from, float to, float t)

From from (t = 0) to to (t = 1) with an ease in and out; t is kept between 0 and 1.

SmoothDamp

csharp
public static float SmoothDamp(float current, float target, ref float currentVelocity, float smoothTime, float maxSpeed, float deltaTime)

Critically damped spring towards target (Game Programming Gems 4, 1.10).

csharp
public static float SmoothDamp(float current, float target, ref float currentVelocity, float smoothTime, float maxSpeed)

SmoothDamp over this frame (Time.deltaTime), at maxSpeed at most.

csharp
public static float SmoothDamp(float current, float target, ref float currentVelocity, float smoothTime)

SmoothDamp over this frame (Time.deltaTime), at any speed.

Repeat

csharp
public static float Repeat(float t, float length)

t looped into [0, length).

PingPong

csharp
public static float PingPong(float t, float length)

t going back and forth between 0 and length.

DeltaAngle

csharp
public static float DeltaAngle(float current, float target)

Shortest difference between two angles in degrees, in [-180, 180].

Approximately

csharp
public static bool Approximately(float a, float b)

Equal up to a relative tolerance (or a tiny absolute one near zero).

IsPowerOfTwo

csharp
public static bool IsPowerOfTwo(int value)

value is a power of two.

NextPowerOfTwo

csharp
public static int NextPowerOfTwo(int value)

The smallest power of two at or above value.

ClosestPowerOfTwo

csharp
public static int ClosestPowerOfTwo(int value)

The power of two nearest to value (halfway: the larger).