Class Mathf
- Namespace
- Godot
- Assembly
- GodotSharp.dll
Provides constants and static methods for common mathematical functions.
public static class Mathf
- Inheritance
-
Mathf
- Inherited Members
Fields
E
The natural number e
.
public const float E = 2.7182817
Field Value
Epsilon
A very small number used for float comparison with error tolerance.
1e-06 with single-precision floats, but 1e-14 if REAL_T_IS_DOUBLE
.
public const float Epsilon = 1E-06
Field Value
Inf
Positive infinity. For negative infinity, use -Mathf.Inf
.
public const float Inf = Infinity
Field Value
NaN
"Not a Number", an invalid value. NaN
has special properties, including
that it is not equal to itself. It is output by some invalid operations,
such as dividing zero by zero.
public const float NaN = NaN
Field Value
Pi
Constant that represents how many times the diameter of a circle
fits around its perimeter. This is equivalent to Mathf.Tau / 2
.
public const float Pi = 3.1415927
Field Value
Sqrt2
The square root of 2.
public const float Sqrt2 = 1.4142135
Field Value
Tau
The circle constant, the circumference of the unit circle in radians.
public const float Tau = 6.2831855
Field Value
Methods
Abs(double)
Returns the absolute value of s
(i.e. positive value).
public static double Abs(double s)
Parameters
s
doubleThe input number.
Returns
- double
The absolute value of
s
.
Abs(int)
Returns the absolute value of s
(i.e. positive value).
public static int Abs(int s)
Parameters
s
intThe input number.
Returns
- int
The absolute value of
s
.
Abs(float)
Returns the absolute value of s
(i.e. positive value).
public static float Abs(float s)
Parameters
s
floatThe input number.
Returns
- float
The absolute value of
s
.
Acos(double)
Returns the arc cosine of s
in radians.
Use to get the angle of cosine s
.
public static double Acos(double s)
Parameters
s
doubleThe input cosine value. Must be on the range of -1.0 to 1.0.
Returns
- double
An angle that would result in the given cosine value. On the range
0
toTau/2
.
Acos(float)
Returns the arc cosine of s
in radians.
Use to get the angle of cosine s
.
public static float Acos(float s)
Parameters
s
floatThe input cosine value. Must be on the range of -1.0 to 1.0.
Returns
- float
An angle that would result in the given cosine value. On the range
0
toTau/2
.
Acosh(double)
Returns the hyperbolic arc (also called inverse) cosine of s
in radians.
Use it to get the angle from an angle's cosine in hyperbolic space if
s
is larger or equal to 1.
public static double Acosh(double s)
Parameters
s
doubleThe input hyperbolic cosine value.
Returns
- double
An angle that would result in the given hyperbolic cosine value.
Acosh(float)
Returns the hyperbolic arc (also called inverse) cosine of s
in radians.
Use it to get the angle from an angle's cosine in hyperbolic space if
s
is larger or equal to 1.
public static float Acosh(float s)
Parameters
s
floatThe input hyperbolic cosine value.
Returns
- float
An angle that would result in the given hyperbolic cosine value.
AngleDifference(double, double)
Returns the difference between the two angles,
in range of -Pi, Pi.
When from
and to
are opposite,
returns -Pi if from
is smaller than to
,
or Pi otherwise.
public static double AngleDifference(double from, double to)
Parameters
Returns
- double
The difference between the two angles.
AngleDifference(float, float)
Returns the difference between the two angles,
in range of -Pi, Pi.
When from
and to
are opposite,
returns -Pi if from
is smaller than to
,
or Pi otherwise.
public static float AngleDifference(float from, float to)
Parameters
Returns
- float
The difference between the two angles.
Asin(double)
Returns the arc sine of s
in radians.
Use to get the angle of sine s
.
public static double Asin(double s)
Parameters
s
doubleThe input sine value. Must be on the range of -1.0 to 1.0.
Returns
- double
An angle that would result in the given sine value. On the range
-Tau/4
toTau/4
.
Asin(float)
Returns the arc sine of s
in radians.
Use to get the angle of sine s
.
public static float Asin(float s)
Parameters
s
floatThe input sine value. Must be on the range of -1.0 to 1.0.
Returns
- float
An angle that would result in the given sine value. On the range
-Tau/4
toTau/4
.
Asinh(double)
Returns the hyperbolic arc (also called inverse) sine of s
in radians.
Use it to get the angle from an angle's sine in hyperbolic space if
s
is larger or equal to 1.
public static double Asinh(double s)
Parameters
s
doubleThe input hyperbolic sine value.
Returns
- double
An angle that would result in the given hyperbolic sine value.
Asinh(float)
Returns the hyperbolic arc (also called inverse) sine of s
in radians.
Use it to get the angle from an angle's sine in hyperbolic space if
s
is larger or equal to 1.
public static float Asinh(float s)
Parameters
s
floatThe input hyperbolic sine value.
Returns
- float
An angle that would result in the given hyperbolic sine value.
Atan(double)
Returns the arc tangent of s
in radians.
Use to get the angle of tangent s
.
The method cannot know in which quadrant the angle should fall.
See Atan2(double, double) if you have both y
and x
.
public static double Atan(double s)
Parameters
s
doubleThe input tangent value.
Returns
- double
An angle that would result in the given tangent value. On the range
-Tau/4
toTau/4
.
Atan(float)
Returns the arc tangent of s
in radians.
Use to get the angle of tangent s
.
The method cannot know in which quadrant the angle should fall.
See Atan2(float, float) if you have both y
and x
.
public static float Atan(float s)
Parameters
s
floatThe input tangent value.
Returns
- float
An angle that would result in the given tangent value. On the range
-Tau/4
toTau/4
.
Atan2(double, double)
Returns the arc tangent of y
and x
in radians.
Use to get the angle of the tangent of y/x
. To compute the value, the method takes into
account the sign of both arguments in order to determine the quadrant.
Important note: The Y coordinate comes first, by convention.
public static double Atan2(double y, double x)
Parameters
y
doubleThe Y coordinate of the point to find the angle to.
x
doubleThe X coordinate of the point to find the angle to.
Returns
- double
An angle that would result in the given tangent value. On the range
-Tau/2
toTau/2
.
Atan2(float, float)
Returns the arc tangent of y
and x
in radians.
Use to get the angle of the tangent of y/x
. To compute the value, the method takes into
account the sign of both arguments in order to determine the quadrant.
Important note: The Y coordinate comes first, by convention.
public static float Atan2(float y, float x)
Parameters
y
floatThe Y coordinate of the point to find the angle to.
x
floatThe X coordinate of the point to find the angle to.
Returns
- float
An angle that would result in the given tangent value. On the range
-Tau/2
toTau/2
.
Atanh(double)
Returns the hyperbolic arc (also called inverse) tangent of s
in radians.
Use it to get the angle from an angle's tangent in hyperbolic space if
s
is between -1 and 1 (non-inclusive).
public static double Atanh(double s)
Parameters
s
doubleThe input hyperbolic tangent value.
Returns
- double
An angle that would result in the given hyperbolic tangent value.
Atanh(float)
Returns the hyperbolic arc (also called inverse) tangent of s
in radians.
Use it to get the angle from an angle's tangent in hyperbolic space if
s
is between -1 and 1 (non-inclusive).
public static float Atanh(float s)
Parameters
s
floatThe input hyperbolic tangent value.
Returns
- float
An angle that would result in the given hyperbolic tangent value.
BezierDerivative(double, double, double, double, double)
Returns the derivative at the given t
on a one dimensional Bezier curve defined by
the given control1
, control2
, and end
points.
public static double BezierDerivative(double start, double control1, double control2, double end, double t)
Parameters
start
doubleThe start value for the interpolation.
control1
doubleControl point that defines the bezier curve.
control2
doubleControl point that defines the bezier curve.
end
doubleThe destination value for the interpolation.
t
doubleA value on the range of 0.0 to 1.0, representing the amount of interpolation.
Returns
- double
The resulting value of the interpolation.
BezierDerivative(float, float, float, float, float)
Returns the derivative at the given t
on a one dimensional Bezier curve defined by
the given control1
, control2
, and end
points.
public static float BezierDerivative(float start, float control1, float control2, float end, float t)
Parameters
start
floatThe start value for the interpolation.
control1
floatControl point that defines the bezier curve.
control2
floatControl point that defines the bezier curve.
end
floatThe destination value for the interpolation.
t
floatA value on the range of 0.0 to 1.0, representing the amount of interpolation.
Returns
- float
The resulting value of the interpolation.
BezierInterpolate(double, double, double, double, double)
Returns the point at the given t
on a one-dimensional Bezier curve defined by
the given control1
, control2
, and end
points.
public static double BezierInterpolate(double start, double control1, double control2, double end, double t)
Parameters
start
doubleThe start value for the interpolation.
control1
doubleControl point that defines the bezier curve.
control2
doubleControl point that defines the bezier curve.
end
doubleThe destination value for the interpolation.
t
doubleA value on the range of 0.0 to 1.0, representing the amount of interpolation.
Returns
- double
The resulting value of the interpolation.
BezierInterpolate(float, float, float, float, float)
Returns the point at the given t
on a one-dimensional Bezier curve defined by
the given control1
, control2
, and end
points.
public static float BezierInterpolate(float start, float control1, float control2, float end, float t)
Parameters
start
floatThe start value for the interpolation.
control1
floatControl point that defines the bezier curve.
control2
floatControl point that defines the bezier curve.
end
floatThe destination value for the interpolation.
t
floatA value on the range of 0.0 to 1.0, representing the amount of interpolation.
Returns
- float
The resulting value of the interpolation.
Ceil(double)
Rounds s
upward (towards positive infinity).
public static double Ceil(double s)
Parameters
s
doubleThe number to ceil.
Returns
- double
The smallest whole number that is not less than
s
.
Ceil(float)
Rounds s
upward (towards positive infinity).
public static float Ceil(float s)
Parameters
s
floatThe number to ceil.
Returns
- float
The smallest whole number that is not less than
s
.
CeilToInt(double)
Rounds s
upward (towards positive infinity).
This is the same as Ceil(double), but returns an int.
public static int CeilToInt(double s)
Parameters
s
doubleThe number to ceil.
Returns
- int
The smallest whole number that is not less than
s
.
CeilToInt(float)
Rounds s
upward (towards positive infinity).
This is the same as Ceil(float), but returns an int.
public static int CeilToInt(float s)
Parameters
s
floatThe number to ceil.
Returns
- int
The smallest whole number that is not less than
s
.
Clamp(double, double, double)
Clamps a value
so that it is not less than min
and not more than max
.
public static double Clamp(double value, double min, double max)
Parameters
value
doubleThe value to clamp.
min
doubleThe minimum allowed value.
max
doubleThe maximum allowed value.
Returns
- double
The clamped value.
Clamp(int, int, int)
Clamps a value
so that it is not less than min
and not more than max
.
public static int Clamp(int value, int min, int max)
Parameters
Returns
- int
The clamped value.
Clamp(float, float, float)
Clamps a value
so that it is not less than min
and not more than max
.
public static float Clamp(float value, float min, float max)
Parameters
value
floatThe value to clamp.
min
floatThe minimum allowed value.
max
floatThe maximum allowed value.
Returns
- float
The clamped value.
Cos(double)
Returns the cosine of angle s
in radians.
public static double Cos(double s)
Parameters
s
doubleThe angle in radians.
Returns
- double
The cosine of that angle.
Cos(float)
Returns the cosine of angle s
in radians.
public static float Cos(float s)
Parameters
s
floatThe angle in radians.
Returns
- float
The cosine of that angle.
Cosh(double)
Returns the hyperbolic cosine of angle s
in radians.
public static double Cosh(double s)
Parameters
s
doubleThe angle in radians.
Returns
- double
The hyperbolic cosine of that angle.
Cosh(float)
Returns the hyperbolic cosine of angle s
in radians.
public static float Cosh(float s)
Parameters
s
floatThe angle in radians.
Returns
- float
The hyperbolic cosine of that angle.
CubicInterpolate(double, double, double, double, double)
Cubic interpolates between two values by the factor defined in weight
with pre and post values.
public static double CubicInterpolate(double from, double to, double pre, double post, double weight)
Parameters
from
doubleThe start value for interpolation.
to
doubleThe destination value for interpolation.
pre
doubleThe value which before "from" value for interpolation.
post
doubleThe value which after "to" value for interpolation.
weight
doubleA value on the range of 0.0 to 1.0, representing the amount of interpolation.
Returns
- double
The resulting value of the interpolation.
CubicInterpolate(float, float, float, float, float)
Cubic interpolates between two values by the factor defined in weight
with pre and post values.
public static float CubicInterpolate(float from, float to, float pre, float post, float weight)
Parameters
from
floatThe start value for interpolation.
to
floatThe destination value for interpolation.
pre
floatThe value which before "from" value for interpolation.
post
floatThe value which after "to" value for interpolation.
weight
floatA value on the range of 0.0 to 1.0, representing the amount of interpolation.
Returns
- float
The resulting value of the interpolation.
CubicInterpolateAngle(double, double, double, double, double)
Cubic interpolates between two rotation values with shortest path
by the factor defined in weight
with pre and post values.
See also LerpAngle(double, double, double).
public static double CubicInterpolateAngle(double from, double to, double pre, double post, double weight)
Parameters
from
doubleThe start value for interpolation.
to
doubleThe destination value for interpolation.
pre
doubleThe value which before "from" value for interpolation.
post
doubleThe value which after "to" value for interpolation.
weight
doubleA value on the range of 0.0 to 1.0, representing the amount of interpolation.
Returns
- double
The resulting value of the interpolation.
CubicInterpolateAngle(float, float, float, float, float)
Cubic interpolates between two rotation values with shortest path
by the factor defined in weight
with pre and post values.
See also LerpAngle(float, float, float).
public static float CubicInterpolateAngle(float from, float to, float pre, float post, float weight)
Parameters
from
floatThe start value for interpolation.
to
floatThe destination value for interpolation.
pre
floatThe value which before "from" value for interpolation.
post
floatThe value which after "to" value for interpolation.
weight
floatA value on the range of 0.0 to 1.0, representing the amount of interpolation.
Returns
- float
The resulting value of the interpolation.
CubicInterpolateAngleInTime(double, double, double, double, double, double, double, double)
Cubic interpolates between two rotation values with shortest path
by the factor defined in weight
with pre and post values.
See also LerpAngle(double, double, double).
It can perform smoother interpolation than
CubicInterpolateAngle(double, double, double, double, double)
by the time values.
public static double CubicInterpolateAngleInTime(double from, double to, double pre, double post, double weight, double toT, double preT, double postT)
Parameters
from
doubleThe start value for interpolation.
to
doubleThe destination value for interpolation.
pre
doubleThe value which before "from" value for interpolation.
post
doubleThe value which after "to" value for interpolation.
weight
doubleA value on the range of 0.0 to 1.0, representing the amount of interpolation.
toT
doublepreT
doublepostT
double
Returns
- double
The resulting value of the interpolation.
CubicInterpolateAngleInTime(float, float, float, float, float, float, float, float)
Cubic interpolates between two rotation values with shortest path
by the factor defined in weight
with pre and post values.
See also LerpAngle(float, float, float).
It can perform smoother interpolation than
CubicInterpolateAngle(float, float, float, float, float)
by the time values.
public static float CubicInterpolateAngleInTime(float from, float to, float pre, float post, float weight, float toT, float preT, float postT)
Parameters
from
floatThe start value for interpolation.
to
floatThe destination value for interpolation.
pre
floatThe value which before "from" value for interpolation.
post
floatThe value which after "to" value for interpolation.
weight
floatA value on the range of 0.0 to 1.0, representing the amount of interpolation.
toT
floatpreT
floatpostT
float
Returns
- float
The resulting value of the interpolation.
CubicInterpolateInTime(double, double, double, double, double, double, double, double)
Cubic interpolates between two values by the factor defined in weight
with pre and post values.
It can perform smoother interpolation than
CubicInterpolate(double, double, double, double, double)
by the time values.
public static double CubicInterpolateInTime(double from, double to, double pre, double post, double weight, double toT, double preT, double postT)
Parameters
from
doubleThe start value for interpolation.
to
doubleThe destination value for interpolation.
pre
doubleThe value which before "from" value for interpolation.
post
doubleThe value which after "to" value for interpolation.
weight
doubleA value on the range of 0.0 to 1.0, representing the amount of interpolation.
toT
doublepreT
doublepostT
double
Returns
- double
The resulting value of the interpolation.
CubicInterpolateInTime(float, float, float, float, float, float, float, float)
Cubic interpolates between two values by the factor defined in weight
with pre and post values.
It can perform smoother interpolation than
CubicInterpolate(float, float, float, float, float)
by the time values.
public static float CubicInterpolateInTime(float from, float to, float pre, float post, float weight, float toT, float preT, float postT)
Parameters
from
floatThe start value for interpolation.
to
floatThe destination value for interpolation.
pre
floatThe value which before "from" value for interpolation.
post
floatThe value which after "to" value for interpolation.
weight
floatA value on the range of 0.0 to 1.0, representing the amount of interpolation.
toT
floatpreT
floatpostT
float
Returns
- float
The resulting value of the interpolation.
DbToLinear(double)
Converts from decibels to linear energy (audio).
public static double DbToLinear(double db)
Parameters
db
doubleDecibels to convert.
Returns
- double
Audio volume as linear energy.
- See Also
DbToLinear(float)
Converts from decibels to linear energy (audio).
public static float DbToLinear(float db)
Parameters
db
floatDecibels to convert.
Returns
- float
Audio volume as linear energy.
- See Also
DecimalCount(decimal)
Returns the amount of digits after the decimal place.
public static int DecimalCount(decimal s)
Parameters
Returns
- int
The amount of digits.
DecimalCount(double)
Returns the amount of digits after the decimal place.
public static int DecimalCount(double s)
Parameters
s
doubleThe input value.
Returns
- int
The amount of digits.
DegToRad(double)
Converts an angle expressed in degrees to radians.
public static double DegToRad(double deg)
Parameters
deg
doubleAn angle expressed in degrees.
Returns
- double
The same angle expressed in radians.
DegToRad(float)
Converts an angle expressed in degrees to radians.
public static float DegToRad(float deg)
Parameters
deg
floatAn angle expressed in degrees.
Returns
- float
The same angle expressed in radians.
Ease(double, double)
Easing function, based on exponent. The curve
values are:
0
is constant, 1
is linear, 0
to 1
is ease-in, 1
or more is ease-out.
Negative values are in-out/out-in.
public static double Ease(double s, double curve)
Parameters
s
doubleThe value to ease.
curve
double0
is constant,1
is linear,0
to1
is ease-in,1
or more is ease-out.
Returns
- double
The eased value.
Ease(float, float)
Easing function, based on exponent. The curve
values are:
0
is constant, 1
is linear, 0
to 1
is ease-in, 1
or more is ease-out.
Negative values are in-out/out-in.
public static float Ease(float s, float curve)
Parameters
s
floatThe value to ease.
curve
float0
is constant,1
is linear,0
to1
is ease-in,1
or more is ease-out.
Returns
- float
The eased value.
Exp(double)
The natural exponential function. It raises the mathematical
constant e
to the power of s
and returns it.
public static double Exp(double s)
Parameters
s
doubleThe exponent to raise
e
to.
Returns
- double
e
raised to the power ofs
.
Exp(float)
The natural exponential function. It raises the mathematical
constant e
to the power of s
and returns it.
public static float Exp(float s)
Parameters
s
floatThe exponent to raise
e
to.
Returns
- float
e
raised to the power ofs
.
Floor(double)
Rounds s
downward (towards negative infinity).
public static double Floor(double s)
Parameters
s
doubleThe number to floor.
Returns
- double
The largest whole number that is not more than
s
.
Floor(float)
Rounds s
downward (towards negative infinity).
public static float Floor(float s)
Parameters
s
floatThe number to floor.
Returns
- float
The largest whole number that is not more than
s
.
FloorToInt(double)
Rounds s
downward (towards negative infinity).
This is the same as Floor(double), but returns an int.
public static int FloorToInt(double s)
Parameters
s
doubleThe number to floor.
Returns
- int
The largest whole number that is not more than
s
.
FloorToInt(float)
Rounds s
downward (towards negative infinity).
This is the same as Floor(float), but returns an int.
public static int FloorToInt(float s)
Parameters
s
floatThe number to floor.
Returns
- int
The largest whole number that is not more than
s
.
InverseLerp(double, double, double)
Returns a normalized value considering the given range. This is the opposite of Lerp(double, double, double).
public static double InverseLerp(double from, double to, double weight)
Parameters
from
doubleThe start value for interpolation.
to
doubleThe destination value for interpolation.
weight
doubleThe interpolated value.
Returns
- double
The resulting value of the inverse interpolation. The returned value will be between 0.0 and 1.0 if
weight
is betweenfrom
andto
(inclusive).
InverseLerp(float, float, float)
Returns a normalized value considering the given range. This is the opposite of Lerp(float, float, float).
public static float InverseLerp(float from, float to, float weight)
Parameters
from
floatThe start value for interpolation.
to
floatThe destination value for interpolation.
weight
floatThe interpolated value.
Returns
- float
The resulting value of the inverse interpolation. The returned value will be between 0.0 and 1.0 if
weight
is betweenfrom
andto
(inclusive).
IsEqualApprox(double, double)
Returns true if a
and b
are approximately equal
to each other.
The comparison is done using a tolerance calculation with Epsilon.
public static bool IsEqualApprox(double a, double b)
Parameters
Returns
IsEqualApprox(double, double, double)
Returns true if a
and b
are approximately
equal to each other.
The comparison is done using the provided tolerance value.
If you want the tolerance to be calculated for you, use IsEqualApprox(double, double).
public static bool IsEqualApprox(double a, double b, double tolerance)
Parameters
a
doubleOne of the values.
b
doubleThe other value.
tolerance
doubleThe pre-calculated tolerance value.
Returns
IsEqualApprox(float, float)
Returns true if a
and b
are approximately equal
to each other.
The comparison is done using a tolerance calculation with Epsilon.
public static bool IsEqualApprox(float a, float b)
Parameters
Returns
IsEqualApprox(float, float, float)
Returns true if a
and b
are approximately
equal to each other.
The comparison is done using the provided tolerance value.
If you want the tolerance to be calculated for you, use IsEqualApprox(float, float).
public static bool IsEqualApprox(float a, float b, float tolerance)
Parameters
a
floatOne of the values.
b
floatThe other value.
tolerance
floatThe pre-calculated tolerance value.
Returns
IsFinite(double)
Returns whether s
is a finite value, i.e. it is not
NaN, positive infinite, or negative infinity.
public static bool IsFinite(double s)
Parameters
s
doubleThe value to check.
Returns
IsFinite(float)
Returns whether s
is a finite value, i.e. it is not
NaN, positive infinite, or negative infinity.
public static bool IsFinite(float s)
Parameters
s
floatThe value to check.
Returns
IsInf(double)
Returns whether s
is an infinity value (either positive infinity or negative infinity).
public static bool IsInf(double s)
Parameters
s
doubleThe value to check.
Returns
IsInf(float)
Returns whether s
is an infinity value (either positive infinity or negative infinity).
public static bool IsInf(float s)
Parameters
s
floatThe value to check.
Returns
IsNaN(double)
Returns whether s
is a NaN
("Not a Number" or invalid) value.
public static bool IsNaN(double s)
Parameters
s
doubleThe value to check.
Returns
IsNaN(float)
Returns whether s
is a NaN
("Not a Number" or invalid) value.
public static bool IsNaN(float s)
Parameters
s
floatThe value to check.
Returns
IsZeroApprox(double)
Returns true if s
is zero or almost zero.
The comparison is done using a tolerance calculation with Epsilon.
This method is faster than using IsEqualApprox(double, double) with one value as zero.
public static bool IsZeroApprox(double s)
Parameters
s
doubleThe value to check.
Returns
IsZeroApprox(float)
Returns true if s
is zero or almost zero.
The comparison is done using a tolerance calculation with Epsilon.
This method is faster than using IsEqualApprox(float, float) with one value as zero.
public static bool IsZeroApprox(float s)
Parameters
s
floatThe value to check.
Returns
Lerp(double, double, double)
Linearly interpolates between two values by a normalized value. This is the opposite InverseLerp(double, double, double).
public static double Lerp(double from, double to, double weight)
Parameters
from
doubleThe start value for interpolation.
to
doubleThe destination value for interpolation.
weight
doubleA value on the range of 0.0 to 1.0, representing the amount of interpolation.
Returns
- double
The resulting value of the interpolation.
Lerp(float, float, float)
Linearly interpolates between two values by a normalized value. This is the opposite InverseLerp(float, float, float).
public static float Lerp(float from, float to, float weight)
Parameters
from
floatThe start value for interpolation.
to
floatThe destination value for interpolation.
weight
floatA value on the range of 0.0 to 1.0, representing the amount of interpolation.
Returns
- float
The resulting value of the interpolation.
LerpAngle(double, double, double)
Linearly interpolates between two angles (in radians) by a normalized value.
Similar to Lerp(double, double, double), but interpolates correctly when the angles wrap around Tau.
public static double LerpAngle(double from, double to, double weight)
Parameters
from
doubleThe start angle for interpolation.
to
doubleThe destination angle for interpolation.
weight
doubleA value on the range of 0.0 to 1.0, representing the amount of interpolation.
Returns
- double
The resulting angle of the interpolation.
LerpAngle(float, float, float)
Linearly interpolates between two angles (in radians) by a normalized value.
Similar to Lerp(float, float, float), but interpolates correctly when the angles wrap around Tau.
public static float LerpAngle(float from, float to, float weight)
Parameters
from
floatThe start angle for interpolation.
to
floatThe destination angle for interpolation.
weight
floatA value on the range of 0.0 to 1.0, representing the amount of interpolation.
Returns
- float
The resulting angle of the interpolation.
LinearToDb(double)
Converts from linear energy to decibels (audio). This can be used to implement volume sliders that behave as expected (since volume isn't linear).
public static double LinearToDb(double linear)
Parameters
linear
doubleThe linear energy to convert.
Returns
- double
Audio as decibels.
Examples
// "slider" refers to a node that inherits Range such as HSlider or VSlider.
// Its range must be configured to go from 0 to 1.
// Change the bus name if you'd like to change the volume of a specific bus only.
AudioServer.SetBusVolumeDb(AudioServer.GetBusIndex("Master"), GD.LinearToDb(slider.value));
- See Also
LinearToDb(float)
Converts from linear energy to decibels (audio). This can be used to implement volume sliders that behave as expected (since volume isn't linear).
public static float LinearToDb(float linear)
Parameters
linear
floatThe linear energy to convert.
Returns
- float
Audio as decibels.
Examples
// "slider" refers to a node that inherits Range such as HSlider or VSlider.
// Its range must be configured to go from 0 to 1.
// Change the bus name if you'd like to change the volume of a specific bus only.
AudioServer.SetBusVolumeDb(AudioServer.GetBusIndex("Master"), GD.LinearToDb(slider.value));
- See Also
Log(double)
Natural logarithm. The amount of time needed to reach a certain level of continuous growth.
Note: This is not the same as the "log" function on most calculators, which uses a base 10 logarithm.
public static double Log(double s)
Parameters
s
doubleThe input value.
Returns
- double
The natural log of
s
.
Log(float)
Natural logarithm. The amount of time needed to reach a certain level of continuous growth.
Note: This is not the same as the "log" function on most calculators, which uses a base 10 logarithm.
public static float Log(float s)
Parameters
s
floatThe input value.
Returns
- float
The natural log of
s
.
Max(double, double)
Returns the maximum of two values.
public static double Max(double a, double b)
Parameters
Returns
- double
Whichever of the two values is higher.
Max(int, int)
Returns the maximum of two values.
public static int Max(int a, int b)
Parameters
Returns
- int
Whichever of the two values is higher.
Max(float, float)
Returns the maximum of two values.
public static float Max(float a, float b)
Parameters
Returns
- float
Whichever of the two values is higher.
Min(double, double)
Returns the minimum of two values.
public static double Min(double a, double b)
Parameters
Returns
- double
Whichever of the two values is lower.
Min(int, int)
Returns the minimum of two values.
public static int Min(int a, int b)
Parameters
Returns
- int
Whichever of the two values is lower.
Min(float, float)
Returns the minimum of two values.
public static float Min(float a, float b)
Parameters
Returns
- float
Whichever of the two values is lower.
MoveToward(double, double, double)
Moves from
toward to
by the delta
value.
Use a negative delta
value to move away.
public static double MoveToward(double from, double to, double delta)
Parameters
from
doubleThe start value.
to
doubleThe value to move towards.
delta
doubleThe amount to move by.
Returns
- double
The value after moving.
MoveToward(float, float, float)
Moves from
toward to
by the delta
value.
Use a negative delta
value to move away.
public static float MoveToward(float from, float to, float delta)
Parameters
Returns
- float
The value after moving.
NearestPo2(int)
Returns the nearest larger power of 2 for the integer value
.
public static int NearestPo2(int value)
Parameters
value
intThe input value.
Returns
- int
The nearest larger power of 2.
PingPong(double, double)
Returns the value
wrapped between 0
and the length
.
If the limit is reached, the next value the function returned is decreased to the 0
side
or increased to the length
side (like a triangle wave).
If length
is less than zero, it becomes positive.
public static double PingPong(double value, double length)
Parameters
Returns
- double
The ping-ponged value.
PingPong(float, float)
Returns the value
wrapped between 0
and the length
.
If the limit is reached, the next value the function returned is decreased to the 0
side
or increased to the length
side (like a triangle wave).
If length
is less than zero, it becomes positive.
public static float PingPong(float value, float length)
Parameters
Returns
- float
The ping-ponged value.
PosMod(double, double)
Performs a canonical Modulus operation, where the output is on the range [0, b
).
public static double PosMod(double a, double b)
Parameters
Returns
- double
The resulting output.
PosMod(int, int)
Performs a canonical Modulus operation, where the output is on the range [0, b
).
public static int PosMod(int a, int b)
Parameters
Returns
- int
The resulting output.
PosMod(float, float)
Performs a canonical Modulus operation, where the output is on the range [0, b
).
public static float PosMod(float a, float b)
Parameters
Returns
- float
The resulting output.
Pow(double, double)
Returns the result of x
raised to the power of y
.
public static double Pow(double x, double y)
Parameters
Returns
- double
x
raised to the power ofy
.
Pow(float, float)
Returns the result of x
raised to the power of y
.
public static float Pow(float x, float y)
Parameters
Returns
- float
x
raised to the power ofy
.
RadToDeg(double)
Converts an angle expressed in radians to degrees.
public static double RadToDeg(double rad)
Parameters
rad
doubleAn angle expressed in radians.
Returns
- double
The same angle expressed in degrees.
RadToDeg(float)
Converts an angle expressed in radians to degrees.
public static float RadToDeg(float rad)
Parameters
rad
floatAn angle expressed in radians.
Returns
- float
The same angle expressed in degrees.
Remap(double, double, double, double, double)
Maps a value
from [inFrom
, inTo
]
to [outFrom
, outTo
].
public static double Remap(double value, double inFrom, double inTo, double outFrom, double outTo)
Parameters
value
doubleThe value to map.
inFrom
doubleThe start value for the input interpolation.
inTo
doubleThe destination value for the input interpolation.
outFrom
doubleThe start value for the output interpolation.
outTo
doubleThe destination value for the output interpolation.
Returns
- double
The resulting mapped value mapped.
Remap(float, float, float, float, float)
Maps a value
from [inFrom
, inTo
]
to [outFrom
, outTo
].
public static float Remap(float value, float inFrom, float inTo, float outFrom, float outTo)
Parameters
value
floatThe value to map.
inFrom
floatThe start value for the input interpolation.
inTo
floatThe destination value for the input interpolation.
outFrom
floatThe start value for the output interpolation.
outTo
floatThe destination value for the output interpolation.
Returns
- float
The resulting mapped value mapped.
RotateToward(double, double, double)
Rotates from
toward to
by the delta
amount. Will not go past to
.
Similar to MoveToward(double, double, double) but interpolates correctly when the angles wrap around Tau.
If delta
is negative, this function will rotate away from to
, toward the opposite angle, and will not go past the opposite angle.
public static double RotateToward(double from, double to, double delta)
Parameters
from
doubleThe start angle.
to
doubleThe angle to move towards.
delta
doubleThe amount to move by.
Returns
- double
The angle after moving.
RotateToward(float, float, float)
Rotates from
toward to
by the delta
amount. Will not go past to
.
Similar to MoveToward(float, float, float) but interpolates correctly when the angles wrap around Tau.
If delta
is negative, this function will rotate away from to
, toward the opposite angle, and will not go past the opposite angle.
public static float RotateToward(float from, float to, float delta)
Parameters
Returns
- float
The angle after moving.
Round(double)
Rounds s
to the nearest whole number,
with halfway cases rounded towards the nearest multiple of two.
public static double Round(double s)
Parameters
s
doubleThe number to round.
Returns
- double
The rounded number.
Round(float)
Rounds s
to the nearest whole number,
with halfway cases rounded towards the nearest multiple of two.
public static float Round(float s)
Parameters
s
floatThe number to round.
Returns
- float
The rounded number.
RoundToInt(double)
Rounds s
to the nearest whole number.
This is the same as Round(double), but returns an int.
public static int RoundToInt(double s)
Parameters
s
doubleThe number to round.
Returns
- int
The rounded number.
RoundToInt(float)
Rounds s
to the nearest whole number.
This is the same as Round(float), but returns an int.
public static int RoundToInt(float s)
Parameters
s
floatThe number to round.
Returns
- int
The rounded number.
Sign(double)
Returns the sign of s
: -1
or 1
.
Returns 0
if s
is 0
.
public static int Sign(double s)
Parameters
s
doubleThe input number.
Returns
- int
One of three possible values:
1
,-1
, or0
.
Sign(int)
Returns the sign of s
: -1
or 1
.
Returns 0
if s
is 0
.
public static int Sign(int s)
Parameters
s
intThe input number.
Returns
- int
One of three possible values:
1
,-1
, or0
.
Sign(float)
Returns the sign of s
: -1
or 1
.
Returns 0
if s
is 0
.
public static int Sign(float s)
Parameters
s
floatThe input number.
Returns
- int
One of three possible values:
1
,-1
, or0
.
Sin(double)
Returns the sine of angle s
in radians.
public static double Sin(double s)
Parameters
s
doubleThe angle in radians.
Returns
- double
The sine of that angle.
Sin(float)
Returns the sine of angle s
in radians.
public static float Sin(float s)
Parameters
s
floatThe angle in radians.
Returns
- float
The sine of that angle.
SinCos(double)
Returns the sine and cosine of angle s
in radians.
public static (double Sin, double Cos) SinCos(double s)
Parameters
s
doubleThe angle in radians.
Returns
SinCos(float)
Returns the sine and cosine of angle s
in radians.
public static (float Sin, float Cos) SinCos(float s)
Parameters
s
floatThe angle in radians.
Returns
Sinh(double)
Returns the hyperbolic sine of angle s
in radians.
public static double Sinh(double s)
Parameters
s
doubleThe angle in radians.
Returns
- double
The hyperbolic sine of that angle.
Sinh(float)
Returns the hyperbolic sine of angle s
in radians.
public static float Sinh(float s)
Parameters
s
floatThe angle in radians.
Returns
- float
The hyperbolic sine of that angle.
SmoothStep(double, double, double)
Returns a number smoothly interpolated between from
and to
,
based on the weight
. Similar to Lerp(double, double, double),
but interpolates faster at the beginning and slower at the end.
public static double SmoothStep(double from, double to, double weight)
Parameters
from
doubleThe start value for interpolation.
to
doubleThe destination value for interpolation.
weight
doubleA value representing the amount of interpolation.
Returns
- double
The resulting value of the interpolation.
SmoothStep(float, float, float)
Returns a number smoothly interpolated between from
and to
,
based on the weight
. Similar to Lerp(float, float, float),
but interpolates faster at the beginning and slower at the end.
public static float SmoothStep(float from, float to, float weight)
Parameters
from
floatThe start value for interpolation.
to
floatThe destination value for interpolation.
weight
floatA value representing the amount of interpolation.
Returns
- float
The resulting value of the interpolation.
Snapped(double, double)
Snaps float value s
to a given step
.
This can also be used to round a floating point number to an arbitrary number of decimals.
public static double Snapped(double s, double step)
Parameters
Returns
- double
The snapped value.
Snapped(float, float)
Snaps float value s
to a given step
.
This can also be used to round a floating point number to an arbitrary number of decimals.
public static float Snapped(float s, float step)
Parameters
Returns
- float
The snapped value.
Sqrt(double)
Returns the square root of s
, where s
is a non-negative number.
If you need negative inputs, use Complex.
public static double Sqrt(double s)
Parameters
s
doubleThe input number. Must not be negative.
Returns
- double
The square root of
s
.
Sqrt(float)
Returns the square root of s
, where s
is a non-negative number.
If you need negative inputs, use Complex.
public static float Sqrt(float s)
Parameters
s
floatThe input number. Must not be negative.
Returns
- float
The square root of
s
.
StepDecimals(double)
Returns the position of the first non-zero digit, after the decimal point. Note that the maximum return value is 10, which is a design decision in the implementation.
public static int StepDecimals(double step)
Parameters
step
doubleThe input value.
Returns
- int
The position of the first non-zero digit.
Tan(double)
Returns the tangent of angle s
in radians.
public static double Tan(double s)
Parameters
s
doubleThe angle in radians.
Returns
- double
The tangent of that angle.
Tan(float)
Returns the tangent of angle s
in radians.
public static float Tan(float s)
Parameters
s
floatThe angle in radians.
Returns
- float
The tangent of that angle.
Tanh(double)
Returns the hyperbolic tangent of angle s
in radians.
public static double Tanh(double s)
Parameters
s
doubleThe angle in radians.
Returns
- double
The hyperbolic tangent of that angle.
Tanh(float)
Returns the hyperbolic tangent of angle s
in radians.
public static float Tanh(float s)
Parameters
s
floatThe angle in radians.
Returns
- float
The hyperbolic tangent of that angle.
Wrap(double, double, double)
Wraps value
between min
and max
.
Usable for creating loop-alike behavior or infinite surfaces.
If min
is 0
, this is equivalent
to PosMod(double, double), so prefer using that instead.
public static double Wrap(double value, double min, double max)
Parameters
value
doubleThe value to wrap.
min
doubleThe minimum allowed value and lower bound of the range.
max
doubleThe maximum allowed value and upper bound of the range.
Returns
- double
The wrapped value.
Wrap(int, int, int)
Wraps value
between min
and max
.
Usable for creating loop-alike behavior or infinite surfaces.
If min
is 0
, this is equivalent
to PosMod(int, int), so prefer using that instead.
public static int Wrap(int value, int min, int max)
Parameters
value
intThe value to wrap.
min
intThe minimum allowed value and lower bound of the range.
max
intThe maximum allowed value and upper bound of the range.
Returns
- int
The wrapped value.
Wrap(float, float, float)
Wraps value
between min
and max
.
Usable for creating loop-alike behavior or infinite surfaces.
If min
is 0
, this is equivalent
to PosMod(float, float), so prefer using that instead.
public static float Wrap(float value, float min, float max)
Parameters
value
floatThe value to wrap.
min
floatThe minimum allowed value and lower bound of the range.
max
floatThe maximum allowed value and upper bound of the range.
Returns
- float
The wrapped value.