Class Math
Provides mathematics functions. this is a high-level wrapper for Mathf.
Consts
e
e (natural constant).
public const float e = 2.718281f;
pi
π.
public const float pi = 3.141592f;
pi2
τ (2π).
public const float pi2 = 2f * pi;
deg2Rad
π/180.
public const float deg2Rad = pi / 180f;
rad2deg
180/π.
public const float rad2deg = 180f / pi;
Methods
LogE(float value)
Returns the natural (base e) logarithm of value.
public static float LogE(float value)
Log10(float value)
Returns the base 10 logarithm of value.
public static float Log10(float value)
Log(float value, float baseNumber)
Returns the base baseNumber logarithm of value.
public static float Log(float value, float baseNumber)
Factorial(float naturalNumber)
Returns the factorial of the naturalNumber.
public static float Factorial(float naturalNumber)
GetPow10(int places)
Returns the power of 10 for the specified number of decimal places.
public static float GetPow10(int places)
GetPow10Negative(int places)
Calculates the negative power of 10 for the specified number of decimal places.
public static float GetPow10Negative(int places)
Overflow(float value, float min, float max)
If the value is outside the [min, max], return the exceeded value.
public static float Overflow(float value, float min, float max)
Overflow(float value, float min, float max, float interval)
Returns the interval ratio if value outside the interval [min, max].
public static float Overflow(float value, float min, float max, float interval)
Overflow(float value, float min, float max, float overflow)
public static bool Overflow(float value, float min, float max, float overflow)
Square(float value)
Returns the square of the value.
public static float Square(float value)
Sqrt(float value)
Returns the square root of the value.
public static float Sqrt(float value)
Exp(float exponent)
Returns natural constant e raised to the power exponent.
public static float Exp(float exponent)
Pow(float baseNumber, float exponent)
Returns baseNumber raised to the power exponent.
public static float Pow(float baseNumber, float exponent)
Lerp(float a, float b, float t)
Linearly interpolates between [a, b] by t.
public static float Lerp(float a, float b, float t)
Lerp01(float a, float b, float t)
Linearly interpolates between [a, b] by t.
The t will be constrained to the interval [0, 1].
public static float Lerp01(float a, float b, float t)
SmoothStep(float a, float b, float t)
Smoothly interpolates between [a, b] by t.
The t will be constrained to the interval [0, 1].
public static float SmoothStep(float a, float b, float t)
Clamp(int value, int min, int max)
Clamp the value within [min, max].
public static int Clamp(int value, int min, int max)
Clamp(int value, int min, int max)
Clamp the value within [min, max].
public static bool Clamp(int value, int min, int max)
Clamp(float value, float min, float max)
Clamp the value within [min, max].
public static float Clamp(float value, float min, float max)
Clamp(float value, float min, float max)
Clamp the value within [min, max].
public static bool Clamp(float value, float min, float max)
CeilToInt(float value)
public static int CeilToInt(float value)
Clamp01(float value)
Clamp the value within [0, 1].
public static float Clamp01(float value)
Clamp01(float value)
Clamp value within [0, 1].
public static bool Clamp01(float value)
Remap(float value, float minValueBefore, float maxValueBefore, float minValueAfter, float maxValueAfter)
Map value in the interval [minValueBefore, maxValueBefore] to the interval [minValueAfter, maxValueAfter].
public static float Remap(float value, float minValueBefore, float maxValueBefore, float minValueAfter, float maxValueAfter)
ToInt(float value)
public static int ToInt(float value)
Ceiling(float value)
Get the smallest integer greater than or equal to value.
public static float Ceiling(float value)
Floor(float value)
Get the largest integer less than or equal to value.
public static float Floor(float value)
Round(float value)
Returns value rounded to the nearest integer (Only consider one decimal place).
public static int Round(float value)
Round(float value, int places, [bool round = true])
Returns value rounded to the nearest integer.
public static float Round(float value, int places, [bool round = true])
Sign(float value)
Get sign of value.
public static float Sign(float value)
Sign(bool value)
Get sign of value.
public static float Sign(bool value)
SignZero(float value)
Get sign of value.
public static float SignZero(float value)
Approximate(float a, float b)
Return true if a approximates b.
public static bool Approximate(float a, float b)
Abs(int value)
Get the absolute value of value.
public static int Abs(int value)
Abs(float value)
Get the absolute value of value.
public static float Abs(float value)
Average(float a, float b)
Get average value of a + b.
public static float Average(float a, float b)
Average(float a, float b, float c)
public static float Average(float a, float b, float c)
Average(float a, float b, float c, float d)
public static float Average(float a, float b, float c, float d)
Max(int a, int b)
public static int Max(int a, int b)
Max(int[] values)
public static int Max(int[] values)
Max(Vector2Int vector2Int)
public static int Max(Vector2Int vector2Int)
Max(float a, float b)
public static float Max(float a, float b)
Max(float[] values)
public static float Max(float[] values)
Max(Vector2 vector2)
public static float Max(Vector2 vector2)
Min(int a, int b)
public static int Min(int a, int b)
Min(int[] values)
public static int Min(int[] values)
Min(Vector2Int vector2Int)
public static int Min(Vector2Int vector2Int)
Min(float[] values)
public static float Min(float[] values)
Min(float a, float b)
public static float Min(float a, float b)
Min(Vector2 vector2)
public static float Min(Vector2 vector2)
MinMax(float a, float b, float min, float max)
Calculate the maximum and minimum values of a and b.
public static void MinMax(float a, float b, float min, float max)
MinMax(float a, float b, float c, float min, float max)
Calculate the maximum and minimum values of a, b, c.
public static void MinMax(float a, float b, float c, float min, float max)
MinMax(float a, float b, float c, float d, float min, float max)
Calculate the maximum and minimum values of a, b, c, d.
public static void MinMax(float a, float b, float c, float d, float min, float max)
MinMax(float[] values, float min, float max)
Calculate the maximum and minimum values in values.
public static void MinMax(float[] values, float min, float max)
Repeat(float value, float length)
Returns the repeated value of value for length.
public static float Repeat(float value, float length)
MoveTowards(float current, float target, float delta)
Moves a value current towards target.
public static float MoveTowards(float current, float target, float delta)
MoveTowards(float current, float target, float delta)
Moves a value current towards target.
public static bool MoveTowards(float current, float target, float delta)
Range(int start, int end)
Generates a integral sequence [start, end].
public static IEnumerable<int> Range(int start, int end)
Sin(float radians)
Returns the sine of radians.
public static float Sin(float radians)
Cos(float radians)
Returns the cosine of radians.
public static float Cos(float radians)
Tan(float radians)
Returns the tangent of radians.
public static float Tan(float radians)
Cot(float radians)
Returns the cotangent of radians.
public static float Cot(float radians)
SinDeg(float degrees)
Returns the sine of degrees.
public static float SinDeg(float degrees)
CosDeg(float degrees)
Returns the cosine of degrees.
public static float CosDeg(float degrees)
TanDeg(float degrees)
Returns the tangent of degrees.
public static float TanDeg(float degrees)
CotDeg(float degrees)
Returns the cotangent of degrees.
public static float CotDeg(float degrees)
Asin(float sin)
Returns the arc sine of sin.
public static float Asin(float sin)
Acos(float cos)
Returns the arc cosine of cos.
public static float Acos(float cos)
ATan(float tan)
public static float ATan(float tan)
Atan2(float y, float x)
public static float Atan2(float y, float x)
Atan2(Vector2 direction)
public static float Atan2(Vector2 direction)
ProjectToPlane(Vector3 position, Vector3 planeOrigin, Vector3 planeNormal, Vector3 projectionDirection, Vector3 projectionPosition)
将点 position 按照方向 projectionDirection 投影到以平面点 planeOrigin 和平面法线 planeNormal 定义的平面中
public static bool ProjectToPlane(Vector3 position, Vector3 planeOrigin, Vector3 planeNormal, Vector3 projectionDirection, Vector3 projectionPosition)
IsInTriangle(Transform transform, Vector3 position, float angle, float length)
点 position 是否在三角形内.
三角形位于xz平面
public static bool IsInTriangle(Transform transform, Vector3 position, float angle, float length)
IsInTriangularPrism(Transform transform, Vector3 position, float angle, float length, float height)
点 position 是否在三棱柱内.
三棱柱位于xz平面, height 为y轴
public static bool IsInTriangularPrism(Transform transform, Vector3 position, float angle, float length, float height)
IsInSector(Transform transform, Vector3 position, float angle, float sideLength)
点 position 是否在扇形内.
该扇形位于xz平面
public static bool IsInSector(Transform transform, Vector3 position, float angle, float sideLength)
IsInSector(Transform transform, Vector3 position, float angle, float sideLength, float height)
点 position 是否在扇形柱内.
扇形柱位于xz平面, height 为y轴
public static bool IsInSector(Transform transform, Vector3 position, float angle, float sideLength, float height)
IsInBallCone(Transform transform, Vector3 position, float angle, float sideLength)
点 position 是否在球锥内
public static bool IsInBallCone(Transform transform, Vector3 position, float angle, float sideLength)
IsInCircularCone(Transform transform, Vector3 position, float angle, float length)
点 position 是否在圆锥内
public static bool IsInCircularCone(Transform transform, Vector3 position, float angle, float length)
IsInViewFrustum(Camera camera, Vector3 position)
判断点 position 是否位于相机 camera 视锥体内
public static bool IsInViewFrustum(Camera camera, Vector3 position)
InRange(float value, float min, float max)
Returns true if value within [min, max].
public static bool InRange(float value, float min, float max)
IsPrime(int number)
Returns true if number is a prime number.
public static bool IsPrime(int number)
IsEven(int number)
Returns true if number is a even number.
public static bool IsEven(int number)