Built-in functions: math_length()

The function math_length() calculates the length of a 2D vector.

Declaration

Form 1:

float math_length( point aPoint )

Form 1:

float math_length( float aX, float aY )

Parameters

aPoint

The 2D vector to calculate the length. The parameter contains the x and y components of the vector.

aX, aY

The components of the 2D vector to calculate the length.

Discussion

The function math_length() calculates the length of a vector specified in the parameters of the function. In its first form the components of the vector are passed in a point parameter aPoint. The second form, in turn, allows the vector components to be passed individually in the both float parameters aX and aY. For example:

var point p = <2,1>; var float x = 2.0; var float y = 1.0; var float l1 = math_length( p ); // l1 = 2.23606801 var float l2 = math_length( x, y ); // l2 = 2.23606801

See also the point instant property length.