Home :: Tutorials :: Geometry

1. Introduction
2. Reference
1. Methods
2. Properties

## Introduction

Point2D is a JavaScript object used to encapsulate a 2-dimensional coordinate. This code is used in the 2D Geometry section of this site.

## Reference

### Methods

constructor - new Point2D(x, y);

This method creates a new Point2D object. All initialization is handled by the init() method. All parameters for this method are described below

init(x, y);

init() initialized all properties for this object.

x is a number that represents the x-coordinate of a point.

y is a number that represents the y-coordinate of a point.

add() returns a new Point2D that is the addition of this object and another Point2D.

addEquals() adds another Point2D to this object. The object is returned to allow multiple point operations to be chained together.

scalarAdd() returns a new Point2D that is equal to the addition of the specified scalar to both coordinates in the object.

scalarAddEquals() adds the specified scalar to both coordinates of the object. The object is returned to allow multiple point operations to be chained together.

subtract(that): Point2D;

subtract() returns a new Point2D that is the subtraction another Point2D from this object.

subtractEquals(that): Point2D;

subtractEquals() subtracts another Point2D from this object. The object is returned to allow multiple point operations to be chained together.

scalarSubtract(scalar): Point2D;

scalarSubtract() returns a new Point2D that is equal to the subtraction of the specified scalar from both coordinates in the object.

scalarSubtractEquals(scalar): Point2D;

scalarSubtractEquals() subtracts the specified scalar from both coordinates of the object. The object is returned to allow multiple point operations to be chained together.

multiply(scalar): Point2D;

multiply() returns a new Point2D that equals this object whose coordinates have been multiplied by the specified scalar amount.

multiplyEquals(scalar): Point2D;

multiplyEquals() multiplies this object's coordinates by the specified amount. The object is returned to allow multiple point operations to be chained together.

divide(scalar): Point2D;

divide() returns a new Point2D that equals this object whose coordinates have been divided by the specified scalar amount.

divideEquals(scalar): Point2D;

divideEquals() divides this object's coordinates by the specified amount. The object is returned to allow multiple point operations to be chained together.

eq(that): boolean;

eq() determines if this object's coordinates match the specified Point2D coordinates.

lt(that): boolean;

lt() determines if any of this object's coordinates are less than the specified Point2D coordinates.

lte(that): boolean;

lte() determines if any of this object's coordinates are less than the specified Point2D coordinates or if all coordinates match.

gt(that): boolean;

gt() determines if any of this object's coordinates are greater than the specified Point2D coordinates.

gte(that): boolean;

gte() determines if any of this object's coordinates are greater than the specified Point2D coordinates or if all coordinates match.

lerp(that, percent) : Point2D;

lerp() performs a linear interpolation between the current Point2D and another Point2D based on the percentage passed to this method.

distanceFrom(that) : float;

distanceFrom() returns the shortest distance between this object and another Point2D.

min(that) : Point2D;

min() returns a new Point2D whose coordinates are the minimum of each coordinate in this object and the specified Point2D.

max(that) : Point2D;

max() returns a new Point2D whose coordinates are the maximum of each coordinate in this object and the specified Point2D.

toString() : string;

toString() converts this object to a string representation.

setXY(x, y);

setXY() sets the current object's coordinates to the specified values.

setFromPoint(point);

setFromPoint() copies the specified point's coordinates to this object.

swap(that);

swap() exchanges the coordinates of this object and the specified Point2D.

### Properties

x is a number that represents the x-coordinate of a point.

y is a number that represents the y-coordinate of a point.