Table of Contents

Class Mathf

Namespace
Lime
Assembly
Lime.dll
public static class Mathf
Inheritance
Mathf
Inherited Members

Fields

DegToRad

public const float DegToRad = 0.017453292

Field Value

float

E

public const float E = 2.7182817

Field Value

float

HalfPi

public const float HalfPi = 1.5707964

Field Value

float

Pi

public const float Pi = 3.1415927

Field Value

float

RadToDeg

public const float RadToDeg = 57.295776

Field Value

float

RandomGenerator

public static Random RandomGenerator

Field Value

Random

TwoPi

public const float TwoPi = 6.2831855

Field Value

float

ZeroTolerance

public const float ZeroTolerance = 1E-06

Field Value

float

Methods

Abs(Vector2)

Returns Vector2 with absolute values of corresponding components of v

public static Vector2 Abs(Vector2 v)

Parameters

v Vector2

Returns

Vector2

Abs(Vector3)

Returns Vector3 with absolute values of corresponding components of v

public static Vector3 Abs(Vector3 v)

Parameters

v Vector3

Returns

Vector3

Abs(float)

Returns absolute value of v. Equals to -v if v less than 0 or v otherwise.

public static float Abs(float v)

Parameters

v float

Returns

float

Acos(float)

public static float Acos(float v)

Parameters

v float

Returns

float

Asin(float)

public static float Asin(float v)

Parameters

v float

Returns

float

Atan2(Vector2)

public static float Atan2(Vector2 v)

Parameters

v Vector2

Returns

float

Atan2(float, float)

public static float Atan2(float y, float x)

Parameters

y float
x float

Returns

float

CalcDistanceToSegment(Vector2, Vector2, Vector2)

public static float CalcDistanceToSegment(Vector2 start, Vector2 end, Vector2 point)

Parameters

start Vector2
end Vector2
point Vector2

Returns

float

CalcLowerPowerOfTwo(int)

public static int CalcLowerPowerOfTwo(int x)

Parameters

x int

Returns

int

CalcUpperPowerOfTwo(int)

public static int CalcUpperPowerOfTwo(int x)

Parameters

x int

Returns

int

CatmullRomSpline(float, Vector2, Vector2, Vector2, Vector2)

public static Vector2 CatmullRomSpline(float t, Vector2 p0, Vector2 p1, Vector2 p2, Vector2 p3)

Parameters

t float
p0 Vector2
p1 Vector2
p2 Vector2
p3 Vector2

Returns

Vector2

CatmullRomSpline(float, Vector3, Vector3, Vector3, Vector3)

public static Vector3 CatmullRomSpline(float t, Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3)

Parameters

t float
p0 Vector3
p1 Vector3
p2 Vector3
p3 Vector3

Returns

Vector3

CatmullRomSpline(float, float, float, float, float)

public static float CatmullRomSpline(float t, float p0, float p1, float p2, float p3)

Parameters

t float
p0 float
p1 float
p2 float
p3 float

Returns

float

Clamp(Vector2, Vector2, Vector2)

public static Vector2 Clamp(Vector2 value, Vector2 min, Vector2 max)

Parameters

value Vector2
min Vector2
max Vector2

Returns

Vector2

Clamp(double, double, double)

public static double Clamp(double value, double min, double max)

Parameters

value double
min double
max double

Returns

double

Clamp(int, int, int)

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

Parameters

value int
min int
max int

Returns

int

Clamp(float, float, float)

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

Parameters

value float
min float
max float

Returns

float

Cos(float)

public static float Cos(float radians)

Parameters

radians float

Returns

float

CubicBezier(float, Vector2, Vector2, Vector2, Vector2)

public static Vector2 CubicBezier(float t, Vector2 p0, Vector2 p1, Vector2 p2, Vector2 p3)

Parameters

t float
p0 Vector2
p1 Vector2
p2 Vector2
p3 Vector2

Returns

Vector2

CubicBezier(float, Vector3, Vector3, Vector3, Vector3)

public static Vector3 CubicBezier(float t, Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3)

Parameters

t float
p0 Vector3
p1 Vector3
p2 Vector3
p3 Vector3

Returns

Vector3

CubicBezier(float, float, float, float, float)

public static float CubicBezier(float t, float p0, float p1, float p2, float p3)

Parameters

t float
p0 float
p1 float
p2 float
p3 float

Returns

float

CubicBezierDerivative(float, Vector2, Vector2, Vector2, Vector2)

public static Vector2 CubicBezierDerivative(float t, Vector2 p0, Vector2 p1, Vector2 p2, Vector2 p3)

Parameters

t float
p0 Vector2
p1 Vector2
p2 Vector2
p3 Vector2

Returns

Vector2

CubicBezierDerivative(float, Vector3, Vector3, Vector3, Vector3)

public static Vector3 CubicBezierDerivative(float t, Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3)

Parameters

t float
p0 Vector3
p1 Vector3
p2 Vector3
p3 Vector3

Returns

Vector3

CubicBezierDerivative(float, float, float, float, float)

public static float CubicBezierDerivative(float t, float p0, float p1, float p2, float p3)

Parameters

t float
p0 float
p1 float
p2 float
p3 float

Returns

float

CubicBezierSecondDerivative(float, float, float, float, float)

public static float CubicBezierSecondDerivative(float t, float p0, float p1, float p2, float p3)

Parameters

t float
p0 float
p1 float
p2 float
p3 float

Returns

float

Erf(double)

Gauss error function. The maximum error is below 1.5 × 10-7.

public static double Erf(double x)

Parameters

x double

Returns

double

Erf(float)

public static float Erf(float x)

Parameters

x float

Returns

float

Exp(float)

public static float Exp(float x)

Parameters

x float

Returns

float

FastInverseSqrt(float)

public static float FastInverseSqrt(float x)

Parameters

x float

Returns

float

HermiteSpline(float, Vector2, Vector2, Vector2, Vector2)

public static Vector2 HermiteSpline(float t, Vector2 p0, Vector2 m0, Vector2 p1, Vector2 m1)

Parameters

t float
p0 Vector2
m0 Vector2
p1 Vector2
m1 Vector2

Returns

Vector2

HermiteSpline(float, Vector3, Vector3, Vector3, Vector3)

public static Vector3 HermiteSpline(float t, Vector3 p0, Vector3 m0, Vector3 p1, Vector3 m1)

Parameters

t float
p0 Vector3
m0 Vector3
p1 Vector3
m1 Vector3

Returns

Vector3

HermiteSpline(float, float, float, float, float)

public static float HermiteSpline(float t, float p0, float m0, float p1, float m1)

Parameters

t float
p0 float
m0 float
p1 float
m1 float

Returns

float

HermiteSplineDerivative(float, Vector2, Vector2, Vector2, Vector2)

public static Vector2 HermiteSplineDerivative(float t, Vector2 p0, Vector2 m0, Vector2 p1, Vector2 m1)

Parameters

t float
p0 Vector2
m0 Vector2
p1 Vector2
m1 Vector2

Returns

Vector2

HermiteSplineDerivative(float, float, float, float, float)

public static float HermiteSplineDerivative(float t, float p0, float m0, float p1, float m1)

Parameters

t float
p0 float
m0 float
p1 float
m1 float

Returns

float

InRange(float, float, float)

public static bool InRange(float x, float upper, float lower)

Parameters

x float
upper float
lower float

Returns

bool

Lerp(float, Vector2, Vector2)

public static Vector2 Lerp(float amount, Vector2 value1, Vector2 value2)

Parameters

amount float
value1 Vector2
value2 Vector2

Returns

Vector2

Lerp(float, Vector3, Vector3)

public static Vector3 Lerp(float amount, Vector3 value1, Vector3 value2)

Parameters

amount float
value1 Vector3
value2 Vector3

Returns

Vector3

Lerp(float, float, float)

public static float Lerp(float amount, float value1, float value2)

Parameters

amount float
value1 float
value2 float

Returns

float

Log(float)

public static float Log(float x)

Parameters

x float

Returns

float

Max(float, float)

public static float Max(float x, float y)

Parameters

x float
y float

Returns

float

Min(float, float)

public static float Min(float x, float y)

Parameters

x float
y float

Returns

float

NormalRandom(IRandom, float, float)

public static float NormalRandom(this IRandom rng, float median, float dispersion)

Parameters

rng IRandom
median float
dispersion float

Returns

float

NormalRandom(Random, float, float)

public static float NormalRandom(this Random rng, float median, float dispersion)

Parameters

rng Random
median float
dispersion float

Returns

float

NormalRandom(float, float)

public static float NormalRandom(float median, float dispersion)

Parameters

median float
dispersion float

Returns

float

Pow(float, float)

public static float Pow(float x, float y)

Parameters

x float
y float

Returns

float

RandomBool()

public static bool RandomBool()

Returns

bool

RandomBool(Random)

public static bool RandomBool(this Random rng)

Parameters

rng Random

Returns

bool

RandomDouble(IRandom, double, double)

public static double RandomDouble(this IRandom rng, double min, double max)

Parameters

rng IRandom
min double
max double

Returns

double

RandomDouble(double, double)

public static double RandomDouble(double min, double max)

Parameters

min double
max double

Returns

double

RandomDouble(Random, double, double)

public static double RandomDouble(this Random rng, double min, double max)

Parameters

rng Random
min double
max double

Returns

double

RandomFloat()

Returns a random floating-point number that is greater than or equal to 0.0, and less than 1.0.

public static float RandomFloat()

Returns

float

A single-precision floating point number that is greater than or equal to 0.0, and less than 1.0.

Remarks

The actual upper bound of the random number returned by this method is 0.99999999999999978.

RandomFloat(IRandom)

public static float RandomFloat(this IRandom rng)

Parameters

rng IRandom

Returns

float

RandomFloat(IRandom, float, float)

public static float RandomFloat(this IRandom rng, float min, float max)

Parameters

rng IRandom
min float
max float

Returns

float

RandomFloat(Random)

Returns a random floating-point number that is greater than or equal to 0.0, and less than 1.0 and produced by specified generator.

public static float RandomFloat(this Random rng)

Parameters

rng Random

The instance of a random generator.

Returns

float

A single-precision floating point number that is greater than or equal to 0.0, and less than 1.0.

Remarks

The actual upper bound of the random number returned by this method is 0.99999999999999978.

RandomFloat(Random, float, float)

Returns a random floating-point number that is within a specified range and produced by specified generator.

public static float RandomFloat(this Random rng, float min, float max)

Parameters

rng Random

The instance of a random generator.

min float

The inclusive lower bound of the random number returned.

max float

The exclusive upper bound of the random number returned.

Returns

float

A single-precision floating point number that is greater than or equal to min, and less than max.

RandomFloat(float, float)

Returns a random floating-point number that is within a specified range.

public static float RandomFloat(float min, float max)

Parameters

min float

The inclusive lower bound of the random number returned.

max float

The exclusive upper bound of the random number returned.

Returns

float

A single-precision floating point number that is greater than or equal to min, and less than max.

RandomInt(IRandom, int)

public static int RandomInt(this IRandom rng, int maxValue)

Parameters

rng IRandom
maxValue int

Returns

int

RandomInt(int)

Returns a non-negative random integer that is less than the specified maximum.

public static int RandomInt(int maxValue)

Parameters

maxValue int

The exclusive upper bound of the random number to be generated. maxValue must be greater than or equal to 0.

Returns

int

A 32-bit signed integer that is greater than or equal to 0, and less than maxValue; that is, the range of return values ordinarily includes 0 but not maxValue. However, if maxValue equals 0, maxValue is returned.

RandomInt(int, int)

Returns a random integer that is within a specified range.

public static int RandomInt(int min, int max)

Parameters

min int

The inclusive lower bound of the random number returned.

max int

The inclusive upper bound of the random number returned. max must be greater than or equal to (min - 1).

Returns

int

A 32-bit signed integer greater than or equal to min and not greater than max; that is, the range of return values includes both min and max. If max equals min or (min - 1), min is returned.

RandomInt(Random, int)

Returns a non-negative random integer that is less than the specified maximum and produced by specified generator.

public static int RandomInt(this Random rng, int maxValue)

Parameters

rng Random

The instance of a random generator.

maxValue int

The exclusive upper bound of the random number to be generated. maxValue must be greater than or equal to 0.

Returns

int

A 32-bit signed integer that is greater than or equal to 0, and less than maxValue; that is, the range of return values ordinarily includes 0 but not maxValue. However, if maxValue equals 0, maxValue is returned.

RandomInt(Random, int, int)

Returns a random integer that is within a specified range and produced by specified generator.

public static int RandomInt(this Random rng, int min, int max)

Parameters

rng Random

The instance of a random generator.

min int

The inclusive lower bound of the random number returned.

max int

The inclusive upper bound of the random number returned. max must be greater than or equal to (min - 1).

Returns

int

A 32-bit signed integer greater than or equal to min and not greater than max; that is, the range of return values includes both min and max. If max equals min or (min - 1), min is returned.

RandomItem<T>(ICollection<T>)

public static T RandomItem<T>(this ICollection<T> objects)

Parameters

objects ICollection<T>

Returns

T

Type Parameters

T

RandomOf<T>(IRandom, ICollection<T>)

public static T RandomOf<T>(this IRandom rng, ICollection<T> objects)

Parameters

rng IRandom
objects ICollection<T>

Returns

T

Type Parameters

T

RandomOf<T>(IRandom, params T[])

public static T RandomOf<T>(this IRandom rng, params T[] objects)

Parameters

rng IRandom
objects T[]

Returns

T

Type Parameters

T

RandomOf<T>(Random, ICollection<T>)

public static T RandomOf<T>(this Random rng, ICollection<T> objects)

Parameters

rng Random
objects ICollection<T>

Returns

T

Type Parameters

T

RandomOf<T>(Random, params T[])

public static T RandomOf<T>(this Random rng, params T[] objects)

Parameters

rng Random
objects T[]

Returns

T

Type Parameters

T

RandomOf<T>(params T[])

public static T RandomOf<T>(params T[] objects)

Parameters

objects T[]

Returns

T

Type Parameters

T

Shuffle<T>(IEnumerable<T>, IRandom)

public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> source, IRandom rng)

Parameters

source IEnumerable<T>
rng IRandom

Returns

IEnumerable<T>

Type Parameters

T

Shuffle<T>(IEnumerable<T>, Random)

public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> source, Random rng = null)

Parameters

source IEnumerable<T>
rng Random

Returns

IEnumerable<T>

Type Parameters

T

Sign(Vector2)

public static Vector2 Sign(Vector2 x)

Parameters

x Vector2

Returns

Vector2

Sign(float)

public static int Sign(float x)

Parameters

x float

Returns

int

Sin(float)

public static float Sin(float radians)

Parameters

radians float

Returns

float

SolveCubicBezier(float, float, float, float, float, float)

Finds cubic Bezier curve parameter t in [0; 1] at which curve evaulates to v. v is also expected to be in [0; 1]

public static float SolveCubicBezier(float v, float p0, float p1, float p2, float p3, float epsilon)

Parameters

v float
p0 float
p1 float
p2 float
p3 float
epsilon float

Returns

float

Sqr(float)

public static float Sqr(float x)

Parameters

x float

Returns

float

Sqrt(float)

public static float Sqrt(float x)

Parameters

x float

Returns

float

UniformRandom(IRandom, float, float)

public static float UniformRandom(this IRandom rng, float median, float dispersion)

Parameters

rng IRandom
median float
dispersion float

Returns

float

UniformRandom(Random, float, float)

public static float UniformRandom(this Random rng, float median, float dispersion)

Parameters

rng Random
median float
dispersion float

Returns

float

UniformRandom(float, float)

public static float UniformRandom(float median, float dispersion)

Parameters

median float
dispersion float

Returns

float

Wrap(int, int, int)

public static int Wrap(int x, int lowerBound, int upperBound)

Parameters

x int
lowerBound int
upperBound int

Returns

int

Wrap(float, float, float)

public static float Wrap(float x, float lowerBound, float upperBound)

Parameters

x float
lowerBound float
upperBound float

Returns

float

Wrap180(float)

public static float Wrap180(float angle)

Parameters

angle float

Returns

float

Wrap360(float)

public static float Wrap360(float angle)

Parameters

angle float

Returns

float