Maths functions and properties

From AGS wiki

Jump to: navigation, search
This article is an entry in the AGS Manual.
Please do not edit this entry except to wikify it, or keep it up-to-date with the manual or current AGS version. Instead you can discuss this article here.
This page was last modified 29 January 2008, and could be out of date with the current AGS version. If you see a page is out of date, please update it!

Owning entry: Scripting

 

Contents

FloatToInt

int FloatToInt(float value, optional RoundDirection)

Converts the supplied floating point value into an integer.

This function is necessary because implicit conversions in the script are not supported.

RoundDirection can be either eRoundDown (the default), eRoundUp or eRoundNearest, which specifies what direction to round the floating point number in.

Example:

 Display("Round down: %d", FloatToInt(10.7));
 Display("Round up: %d", FloatToInt(10.7, eRoundUp));
 Display("Round nearest: %d", FloatToInt(10.7, eRoundNearest));

displays the integer value of 10.7, rounded in the three different ways.

See Also: IntToFloat

IntToFloat

float IntToFloat(int value)

Converts the supplied integer value into a floating point number.

This function is necessary because implicit conversions in the script are not supported.

Example:

 float number = IntToFloat(10);

loads 10.0 into the variable number.

See Also: FloatToInt

Maths.ArcCos

float Maths.ArcCos(float value)

Calculates the arc-cosine, in radians, of the specified value.

To convert an angle in radians to degrees, use Maths.RadiansToDegrees.

Example:

 float angle = Maths.ArcCos(1.0);

calculates the arc-cosine of 1.0 and places it into variable angle.

See Also: Maths.Cos, Maths.DegreesToRadians

Maths.ArcSin

float Maths.ArcSin(float value)

Calculates the arc-sine, in radians, of the specified value.

To convert an angle in radians to degrees, use Maths.RadiansToDegrees.

Example:

 float angle = Maths.ArcSin(0.5);

calculates the arc-sine of 0.5 and places it into variable angle.

See Also: Maths.Sin, Maths.DegreesToRadians

Maths.ArcTan

float Maths.ArcTan(float value)

Calculates the arc-tan, in radians, of the specified value.

To convert an angle in radians to degrees, use Maths.RadiansToDegrees.

Example:

 float angle = Maths.ArcTan(0.5);

calculates the arc-tan of 0.5 and places it into variable angle.

See Also: Maths.ArcTan2, Maths.DegreesToRadians, Maths.Tan

Maths.ArcTan2

float Maths.ArcTan2(float y, float x)

Calculates the arctangent of y/x. This is well defined for every point other than the origin, even if x equals 0 and y does not equal 0. The result is returned in radians.

To convert an angle in radians to degrees, use Maths.RadiansToDegrees.

Example:

 float angle = Maths.ArcTan2(-862.42, 78.5149);

calculates the arc-tan of -862.42 / 78.5149 and places it into variable angle.

See Also: Maths.DegreesToRadians, Maths.ArcTan

Maths.Cos

float Maths.Cos(float radians)

Calculates the cosine of the specified angle (in radians).

To convert an angle in degrees to radians, use Maths.DegreesToRadians.

Example:

 float cosine = Maths.Cos(Maths.DegreesToRadians(360.0));

calculates the cosine of 360 degrees (which is 1.0) and places it into variable cosine.

See Also: Maths.ArcCos, Maths.DegreesToRadians, Maths.Sin, Maths.Tan

Maths.DegreesToRadians

float Maths.DegreesToRadians(float degrees)

Converts the supplied angle in degrees, to the equivalent angle in radians.

Since the trigonometric functions such as Sin, Cos and Tan work in radians, this function is handy if you know the angle you want in degrees.

Example:

 float cosine = Maths.Cos(Maths.DegreesToRadians(360.0));

calculates the cosine of 360 degrees (which is 1.0) and places it into variable cosine.

See Also: Maths.Cos, Maths.RadiansToDegrees, Maths.Sin, Maths.Tan

Maths.Pi

readonly float Maths.Pi

Gets the value of Pi (defined as 3.14159265358979323846).

Example:

 Display("Pi is %f!", Maths.Pi);

displays the value of Pi.

See Also: Maths.Cos, Maths.Sin, Maths.Tan

Maths.RadiansToDegrees

float Maths.RadiansToDegrees(float radians)

Converts the supplied angle in radians, to the equivalent angle in degrees.

Since the trigonometic functions such as Sin, Cos and Tan work in radians, this function is handy to convert the results of one of those functions back to degrees.

Example:

 float halfCircle = Maths.RadiansToDegrees(Maths.Pi);

converts PI radians into degrees (which is 180).

See Also: Maths.Cos, Maths.DegreesToRadians, Maths.Sin, Maths.Tan

Maths.RaiseToPower

float Maths.RaiseToPower(float base, float exponent)

Calculates the value of base raised to the power exponent.

This means that base is multiplied by itself exponent times.

Example:

 float value = Maths.RaiseToPower(4.0, 3.0);

calculates 4 to the power 3 (which is 64).

See Also: Maths.Sqrt

Maths.Sin

float Maths.Sin(float radians)

Calculates the sine of the specified angle (in radians).

To convert an angle in degrees to radians, use Maths.DegreesToRadians.

Example:

 float sine = Maths.Sin(Maths.DegreesToRadians(360.0));

calculates the cosine of 360 degrees (which is 0) and places it into variable sine.

See Also: Maths.ArcSin, Maths.DegreesToRadians, Maths.Cos, Maths.Tan

Maths.Sqrt

float Maths.Sqrt(float value)

Calculates the square root of the supplied value.

The square root is the number which, when multiplied by itself, equals value.

Example:

 Display("The square root of 4 is %d!", FloatToInt(Maths.Sqrt(4.0)));

displays the square root of 4 (rounded down to the nearest integer).

See Also: Maths.Cos, Maths.RaiseToPower, Maths.Sin, Maths.Tan

Maths.Tan

float Maths.Tan(float radians)

Calculates the tangent of the specified angle (in radians).

To convert an angle in degrees to radians, use Maths.DegreesToRadians.

Example:

 float tan = Maths.Tan(Maths.DegreesToRadians(45.0));

calculates the tan of 45 degrees (which is 1.0) and places it into variable tan.

See Also: Maths.ArcTan, Maths.DegreesToRadians, Maths.Cos, Maths.Sin

Personal tools
Advertisement