UnityEngine::Mathd
A struct that provides mathematical constants and functions using double-precision (double) values.
Public Functions
Name | |
---|---|
double | Sin(double d) Returns the sine of the specified angle in radians. |
double | Cos(double d) Returns the cosine of the specified angle in radians. |
double | Tan(double d) Returns the tangent of the specified angle in radians. |
double | Asin(double d) Returns the arcsine of the specified angle in radians. |
double | Acos(double d) Returns the arccosine of the specified angle in radians. |
double | Atan(double d) Returns the arctangent of the specified angle in radians. |
double | Atan2(double y, double x) Returns the arctangent of the quotient of two specified numbers. |
double | Sqrt(double d) Returns the square root of a specified number. |
double | Abs(double d) Returns the absolute value of a specified number. |
int | Abs(int value) Returns the absolute value of a specified 32-bit signed integer. |
double | Min(double a, double b) Returns the smaller of two specified numbers. |
double | Min(params double[] values) Returns the smaller of two or more double-precision floating-point numbers. |
int | Min(int a, int b) Returns the smaller of two specified 32-bit signed integers. |
int | Min(params int[] values) Returns the smaller of two or more 32-bit signed integers. |
double | Max(double a, double b) Returns the larger of two specified double-precision floating-point numbers. |
double | Max(params double[] values) Returns the larger of two or more double-precision floating-point numbers. |
int | Max(int a, int b) Returns the larger of two specified 32-bit signed integers. |
int | Max(params int[] values) Returns the larger of two or more 32-bit signed integers. |
double | Pow(double d, double p) Returns a specified number raised to the power of another specified number. |
double | Exp(double power) Returns e raised to the specified power. |
double | Log(double d) Returns the natural logarithm of a specified number. |
double | Log(double d, double p) Returns the logarithm of a specified number in a specified base. |
double | Log10(double d) Returns the base 10 logarithm of a specified number. |
double | Ceil(double d) Returns the smallest integral value that is greater than or equal to the specified double-precision floating-point number. |
double | Floor(double d) Returns the largest integer less than or equal to the specified double-precision floating-point number. |
double | Round(double d) Rounds a double-precision floating-point value to the nearest integral value. |
int | CeilToInt(double d) Returns the smallest integral value greater than or equal to the specified double-precision floating-point number. |
int | FloorToInt(double d) Returns the largest integer less than or equal to the specified double-precision floating-point number. |
int | RoundToInt(double d) Rounds a double-precision floating-point value to the nearest integer. |
double | Sign(double d) Returns a value indicating the sign of a double-precision floating-point number. |
double | Clamp(double value, double min, double max) Restricts a value to be within a specified range. |
int | Clamp(int value, int min, int max) Restricts a value to be within a specified range. |
double | Clamp01(double value) Clamps a value between 0 and 1. |
double | Lerp(double from, double to, double t) Linearly interpolates between two values. |
double | LerpAngle(double a, double b, double t) Linearly interpolates between two angles. |
double | MoveTowards(double current, double target, double maxDelta) Moves a value towards a target with a maximum step. |
double | MoveTowardsAngle(double current, double target, double maxDelta) Moves an angle towards a target angle with a maximum step. |
double | SmoothStep(double from, double to, double t) Smoothes a value between two values using a Hermite spline. |
double | Gamma(double value, double absmax, double gamma) Applies gamma correction to a value. |
double | InverseLerp(double a, double b, double value) Calculates the linear parameter t that produces the interpolant value within the range [a, b]. |
double | DeltaAngle(double current, double target) Calculates the signed difference between two angles. |
double | Repeat(double value, double length) Loops a value so that it is within a specified range. |
double | PercentageBetween(double value, double min, double max) Calculates the percentage of a specified value between two values. |
double | ClampAndWrap(double value, double min, double max) Clamps a value between two other values and loops it if necessary. |
System.Random | Random(int seed) Creates a random number generator with a given seed. |
double | RandomValue(System.Random rand) Generates a random double-precision floating-point number between 0 (inclusive) and 1 (exclusive). |
int | RandomRange(System.Random rand, int min, int max) Generates a random integer between the specified minimum (inclusive) and maximum (exclusive) values. |
Public Attributes
Name | |
---|---|
const double | PI Represents the mathematical constant π (pi). |
const double | Infinity Represents positive infinity (∞). |
const double | NegativeInfinity Represents negative infinity (-∞). |
const double | Deg2Rad Conversion factor for degrees to radians. |
const double | Rad2Deg Conversion factor for radians to degrees. |
const double | Epsilon Represents the smallest positive double-precision floating-point value greater than zero. |
Public Functions Documentation
function Sin
static double Sin(
double d
)
Returns the sine of the specified angle in radians.
Parameters:
- d An angle in radians.
Return: The sine of the specified angle.
function Cos
static double Cos(
double d
)
Returns the cosine of the specified angle in radians.
Parameters:
- d An angle in radians.
Return: The cosine of the specified angle.
function Tan
static double Tan(
double d
)
Returns the tangent of the specified angle in radians.
Parameters:
- d An angle in radians.
Return: The tangent of the specified angle.
function Asin
static double Asin(
double d
)
Returns the arcsine of the specified angle in radians.
Parameters:
- d An angle in radians.
Return: The arcsine of the specified angle.
function Acos
static double Acos(
double d
)
Returns the arccosine of the specified angle in radians.
Parameters:
- d An angle in radians.
Return: The arccosine of the specified angle.
function Atan
static double Atan(
double d
)
Returns the arctangent of the specified angle in radians.
Parameters:
- d An angle in radians.
Return: The arctangent of the specified angle.
function Atan2
static double Atan2(
double y,
double x
)
Returns the arctangent of the quotient of two specified numbers.
Parameters:
- y The y-coordinate of a point.
- x The x-coordinate of a point.
Return: The arctangent of y / x in radians.
function Sqrt
static double Sqrt(
double d
)
Returns the square root of a specified number.
Parameters:
- d A number.
Return: The positive square root of the specified number.
function Abs
static double Abs(
double d
)
Returns the absolute value of a specified number.
Parameters:
- d A number.
Return: The absolute value of the specified number.
function Abs
static int Abs(
int value
)
Returns the absolute value of a specified 32-bit signed integer.
Parameters:
- value A 32-bit signed integer.
Return: The absolute value of value.
function Min
static double Min(
double a,
double b
)
Returns the smaller of two specified numbers.
Parameters:
- a The first of two double-precision floating-point numbers to compare.
- b The second of two double-precision floating-point numbers to compare.
Return: The smaller of a or b.
function Min
static double Min(
params double[] values
)
Returns the smaller of two or more double-precision floating-point numbers.
Parameters:
- values An array of double-precision floating-point numbers to compare.
Return: The smallest of the values in the array.
function Min
static int Min(
int a,
int b
)
Returns the smaller of two specified 32-bit signed integers.
Parameters:
- a The first of two 32-bit signed integers to compare.
- b The second of two 32-bit signed integers to compare.
Return: The smaller of a or b.
function Min
static int Min(
params int[] values
)
Returns the smaller of two or more 32-bit signed integers.
Parameters:
- values An array of 32-bit signed integers to compare.
Return: The smallest of the values in the array.
function Max
static double Max(
double a,
double b
)
Returns the larger of two specified double-precision floating-point numbers.
Parameters:
- a The first of two double-precision floating-point numbers to compare.
- b The second of two double-precision floating-point numbers to compare.
Return: The larger of a or b.
function Max
static double Max(
params double[] values
)
Returns the larger of two or more double-precision floating-point numbers.
Parameters:
- values An array of double-precision floating-point numbers to compare.
Return: The largest of the values in the array.
function Max
static int Max(
int a,
int b
)
Returns the larger of two specified 32-bit signed integers.
Parameters:
- a The first of two 32-bit signed integers to compare.
- b The second of two 32-bit signed integers to compare.
Return: The larger of a or b.
function Max
static int Max(
params int[] values
)
Returns the larger of two or more 32-bit signed integers.
Parameters:
- values An array of 32-bit signed integers to compare.
Return: The largest of the values in the array.
function Pow
static double Pow(
double d,
double p
)
Returns a specified number raised to the power of another specified number.
Parameters:
- d A double-precision floating-point number to be raised to a power.
- p A double-precision floating-point number that specifies a power.
Return: The number d raised to the power p.
function Exp
static double Exp(
double power
)
Returns e raised to the specified power.
Parameters:
- power A number specifying the power.
Return: The number e raised to the power power.
function Log
static double Log(
double d
)
Returns the natural logarithm of a specified number.
Parameters:
- d A number.
Return: The natural logarithm of d.
function Log
static double Log(
double d,
double p
)
Returns the logarithm of a specified number in a specified base.
Parameters:
- d A number.
- p The base of the logarithm.
Return: The logarithm of d in base p.
function Log10
static double Log10(
double d
)
Returns the base 10 logarithm of a specified number.
Parameters:
- d A number.
Return: The base 10 logarithm of d.
function Ceil
static double Ceil(
double d
)
Returns the smallest integral value that is greater than or equal to the specified double-precision floating-point number.
Parameters:
- d A number.
Return: The smallest integral value that is greater than or equal to d.
function Floor
static double Floor(
double d
)
Returns the largest integer less than or equal to the specified double-precision floating-point number.
Parameters:
- d A number.
Return: The largest integer less than or equal to d.
function Round
static double Round(
double d
)
Rounds a double-precision floating-point value to the nearest integral value.
Parameters:
- d A number.
Return: The integral value nearest to d. If d is halfway between two integers, one of those integers is returned.
function CeilToInt
static int CeilToInt(
double d
)
Returns the smallest integral value greater than or equal to the specified double-precision floating-point number.
Parameters:
- d A number.
Return: The smallest integral value that is greater than or equal to d.
function FloorToInt
static int FloorToInt(
double d
)
Returns the largest integer less than or equal to the specified double-precision floating-point number.
Parameters:
- d A number.
Return: The largest integer less than or equal to d.
function RoundToInt
static int RoundToInt(
double d
)
Rounds a double-precision floating-point value to the nearest integer.
Parameters:
- d A number.
Return: The integer nearest to d. If d is halfway between two integers, the even integer is returned.
function Sign
static double Sign(
double d
)
Returns a value indicating the sign of a double-precision floating-point number.
Parameters:
- d A signed number.
Return: -1 if d is less than zero. 0 if d is zero. 1 if d is greater than zero.
function Clamp
static double Clamp(
double value,
double min,
double max
)
Restricts a value to be within a specified range.
Parameters:
- value The value to clamp.
- min The minimum value. If value is less than min, min will be returned.
- max The maximum value. If value is greater than max, max will be returned.
Return: The clamped value.
function Clamp
static int Clamp(
int value,
int min,
int max
)
Restricts a value to be within a specified range.
Parameters:
- value The value to clamp.
- min The minimum value. If value is less than min, min will be returned.
- max The maximum value. If value is greater than max, max will be returned.
Return: The clamped value.
function Clamp01
static double Clamp01(
double value
)
Clamps a value between 0 and 1.
Parameters:
- value The value to clamp.
Return: The clamped value between 0 and 1.
function Lerp
static double Lerp(
double from,
double to,
double t
)
Linearly interpolates between two values.
Parameters:
- from The start value.
- to The end value.
- t The interpolation factor. Value is clamped between 0 and 1.
Return: The interpolated value.
function LerpAngle
static double LerpAngle(
double a,
double b,
double t
)
Linearly interpolates between two angles.
Parameters:
- a The start angle in degrees.
- b The end angle in degrees.
- t The interpolation factor. Value is clamped between 0 and 1.
Return: The interpolated angle in degrees.
function MoveTowards
static double MoveTowards(
double current,
double target,
double maxDelta
)
Moves a value towards a target with a maximum step.
Parameters:
- current The current value.
- target The target value to move towards.
- maxDelta The maximum step to take towards the target.
Return: The new value moved towards the target.
function MoveTowardsAngle
static double MoveTowardsAngle(
double current,
double target,
double maxDelta
)
Moves an angle towards a target angle with a maximum step.
Parameters:
- current The current angle in degrees.
- target The target angle in degrees to move towards.
- maxDelta The maximum step to take towards the target.
Return: The new angle in degrees moved towards the target angle.
function SmoothStep
static double SmoothStep(
double from,
double to,
double t
)
Smoothes a value between two values using a Hermite spline.
Parameters:
- from The start value.
- to The end value.
- t The interpolation factor. Value is clamped between 0 and 1.
Return: The smoothed value.
function Gamma
static double Gamma(
double value,
double absmax,
double gamma
)
Applies gamma correction to a value.
Parameters:
- value The value to modify.
- absmax The maximum absolute value of the input value.
- gamma The gamma correction value.
Return: The gamma-corrected value.
function InverseLerp
static double InverseLerp(
double a,
double b,
double value
)
Calculates the linear parameter t that produces the interpolant value within the range [a, b].
Parameters:
- a The start value.
- b The end value.
- value The value to interpolate within the range [a, b].
Return: The linear parameter t in the range [0, 1] that produces the interpolant value.
function DeltaAngle
static double DeltaAngle(
double current,
double target
)
Calculates the signed difference between two angles.
Parameters:
- current The current angle in degrees.
- target The target angle in degrees.
Return: The signed difference between the two angles in degrees.
function Repeat
static double Repeat(
double value,
double length
)
Loops a value so that it is within a specified range.
Parameters:
- value The value to loop.
- length Lenght of the loop
Return: The looped value that wraps around if it goes outside the specified range.
function PercentageBetween
static double PercentageBetween(
double value,
double min,
double max
)
Calculates the percentage of a specified value between two values.
Parameters:
- value The value to interpolate between the range [min, max].
- min The minimum value in the range.
- max The maximum value in the range.
Return: The percentage of value between min and max, ranging from 0 to 1.
function ClampAndWrap
static double ClampAndWrap(
double value,
double min,
double max
)
Clamps a value between two other values and loops it if necessary.
Parameters:
- value The value to clamp and loop.
- min The minimum value in the range.
- max The maximum value in the range.
Return: The clamped and looped value that is within the specified range.
function Random
static System.Random Random(
int seed
)
Creates a random number generator with a given seed.
Parameters:
- seed The seed value for the random number generator.
Return: A new System.Random instance with the specified seed.
function RandomValue
static double RandomValue(
System.Random rand
)
Generates a random double-precision floating-point number between 0 (inclusive) and 1 (exclusive).
Parameters:
- rand The random number generator to use.
Return: A random double-precision floating-point number between 0 (inclusive) and 1 (exclusive).
function RandomRange
static int RandomRange(
System.Random rand,
int min,
int max
)
Generates a random integer between the specified minimum (inclusive) and maximum (exclusive) values.
Parameters:
- rand The random number generator to use.
- min The minimum value (inclusive).
- max The maximum value (exclusive).
Return: A random integer between the minimum (inclusive) and maximum (exclusive) values.
Public Attributes Documentation
variable PI
static const double PI = 3.141592653589793d;
Represents the mathematical constant π (pi).
variable Infinity
static const double Infinity = double.PositiveInfinity;
Represents positive infinity (∞).
variable NegativeInfinity
static const double NegativeInfinity = double.NegativeInfinity;
Represents negative infinity (-∞).
variable Deg2Rad
static const double Deg2Rad = 0.01745329d;
Conversion factor for degrees to radians.
variable Rad2Deg
static const double Rad2Deg = 57.29578d;
Conversion factor for radians to degrees.
variable Epsilon
static const double Epsilon = 1.401298E-45d;
Represents the smallest positive double-precision floating-point value greater than zero.