Point2D

A 2D point.

Constructor

new Point2D(x, y)

Creates a new Point2D with the given coordinates.

Parameters:
NameTypeDescription
xnumber

The x-coordinate of the point.

ynumber

The y-coordinate of the point.

Classes

Point2D

Members

direction

Gets the direction angle with respect to (0, 0) of the Point2D.

magnitude

Returns the magnitude of the Point2D.

magnitude_squared

Returns the squared magnitude of the Point2D.

normalized

Returns the normalized Point2D.

x

The x-coordinate of the point.

x

The x-coordinate of the point.

y

The y-coordinate of the point.

y

The y-coordinate of the point.

Methods

angle(other) → {number}

Returns the angle between two Point2Ds.

Parameters:
NameTypeDescription
otherPoint2D

The other point.

Returns:

The angle between the two points.

Type: 
number

clone() → {Point2D}

Clones the Point2D.

Returns:
Type: 
Point2D

distance(other) → {number}

Returns the distance between two Point2Ds.

Parameters:
NameTypeDescription
otherPoint2D

The other point.

Returns:

The distance between the two points.

Type: 
number

distance_squared(other) → {number}

Returns the distance between two Point2Ds.

Parameters:
NameTypeDescription
otherPoint2D

The other point.

Returns:

The distance between the two points.

Type: 
number

dot(other) → {number}

Returns the dot product of Point2D objects.

Parameters:
NameTypeDescription
otherPoint2D

The other point.

Returns:

The dot product of the two points.

Type: 
number

equals(other, toleranceopt) → {boolean}

Checks if two Point2D objects are equal within a given tolerance.

Parameters:
NameTypeAttributesDescription
otherPoint2D

The other point.

tolerancenumber | null<optional>

The tolerance.

Returns:

A boolean indicating whether the two points are equal.

Type: 
boolean

is_finite() → {boolean}

Checks if a point is finite

Returns:

A boolean indicating whether the point is finite.

Type: 
boolean

project_onto_line(start, end) → {number}

Projects a point onto a line given the start and end points of the line.

Parameters:
NameTypeDescription
startPoint2D

The start point of the line.

endPoint2D

The end point of the line.

Returns:

The proportion of the line.

Type: 
number

rotate_around(center, angle) → {Point2D}

Returns the Point2D rotated around a given center point by a given angle.

Parameters:
NameTypeDescription
centerPoint2D

The center point to rotate around.

anglenumber

The angle to rotate by.

Returns:

The rotated point.

Type: 
Point2D

(static) from_polar(radius, angle) → {Point2D}

Gets a cartesian point from polar coordinates.

Parameters:
NameTypeDescription
radiusnumber

The radius of the point.

anglenumber

The angle of the point.

Returns:

A 2D point.

Type: 
Point2D

(static) lerp(point1, point2, t) → {Point2D}

Linearly interpolates between two Point2D objects.

Parameters:
NameTypeDescription
point1Point2D

The start point.

point2Point2D

The end point.

tnumber

The progress value.

Returns:

The interpolated point.

Type: 
Point2D