Hide menu
Loading...
Searching...
No Matches
Vector2d

Defines vector in 2D space.

Constructors

new Vector2d()

new Vector2d(x?, y?): Vector2d

Parameters

x?

number

X coordinate of 2D vector.

y?

number

Y coordinate of 2D vector.

Returns

Vector2d

Accessors

x

Get Signature

get x(): number

Returns x coordinate of 2D vector.

Returns

number

Set Signature

set x(x): void

Sets x coordinate of 2D vector.

Parameters

x

number

X coordinate.

Returns

void


y

Get Signature

get y(): number

Returns y coordinate of 2D vector.

Returns

number

Set Signature

set y(y): void

Sets y coordinate of 2D vector.

Parameters

y

number

Y coordinate.

Returns

void

Methods

add()

add(other): this

Adds other vector coordinates to this vector coordinates.

Parameters

other

Vector2d

Other vector.

Returns

this


added()

added(other): Vector2d

Returns new Vector2d object with coordinates received by performing a add() operation to this object.

Parameters

other

Vector2d

Other vector.

Returns

Vector2d


angle()

angle(other): number

Returns angle between this and other vectors.

Parameters

other

Vector2d

Other vector.

Returns

number


clone()

clone(): Vector2d

Creates new Vector object with coordinates same as this.

Returns

Vector2d


copy()

copy(other): this

Copies the coordinates of the other vector to this.

Parameters

other

Vector2d

Copied object.

Returns

this


crossed()

crossed(other): number

Returns cross product of this and other vectors.

Parameters

other

Vector2d

Other vector.

Returns

number


divide()

divide(scalar): this

Divide this vector coordinates by scalar value.

Parameters

scalar

number

Scalar value.

Returns

this


divided()

divided(scalar): Vector2d

Returns new Vector2d object with coordinates received by performing a divide() operation to this object.

Parameters

scalar

number

Scalar value.

Returns

Vector2d


dot()

dot(other): number

Returns dot product of this and other vector.

Parameters

other

Vector2d

Other vector.

Returns

number


isEqual()

isEqual(other, tolerance?): boolean

Returns true if other vector coordinates are equal to this vector coordinated within provided tolerance (1e-7 by default). Returns false otherwise.

Parameters

other

Vector2d

Other 2D vector.

tolerance?

number

Coordinates comparison tolerance;

Returns

boolean


isNormal()

isNormal(other, tolerance?): boolean

Returns true if other vector is perpendicular to this within provided tolerance (1e-7 by default).

Parameters

other

Vector2d

Other vector.

tolerance?

number

Returns

boolean


isOpposite()

isOpposite(other, tolerance?): boolean

Returns true if other vector is opposite to this within provided tolerance (1e-7 by default).

Parameters

other

Vector2d

Other vector.

tolerance?

number

Returns

boolean


isParallel()

isParallel(other, tolerance?): boolean

Returns true if other vector is parallel to this within provided tolerance (1e-7 by default).

Parameters

other

Vector2d

Other vector.

tolerance?

number

Returns

boolean


length()

length(): number

Returns length of the vector.

Returns

number


multiplied()

Call Signature

multiplied(other): Vector2d

Returns new Vector2d object with coordinates received by performing a multiply() operation to this object.

Parameters

other

Vector2d

Other vector.

Returns

Vector2d

Call Signature

multiplied(matrix): Vector2d

Returns new Vector2d object with coordinates received by performing a multiply() operation to this object.

Parameters

matrix

Matrix2d

2D matrix.

Returns

Vector2d

Call Signature

multiplied(scalar): Vector2d

Returns new Vector2d object with coordinates received by performing a multiply() operation to this object.

Parameters

scalar

number

Scalar value.

Returns

Vector2d


multiply()

Call Signature

multiply(other): this

Multiplies this vector coordinates with other vector coordinates.

Parameters

other

Vector2d

Other vector.

Returns

this

Call Signature

multiply(matrix): this

Multiplies this vector coordinates with 2D matrix.

Parameters

matrix

Matrix2d

2D matrix.

Returns

this

Call Signature

multiply(scalar): this

Multiplies this vector coordinates with scalar value.

Parameters

scalar

number

Scalar value.

Returns

this


normalize()

normalize(): this

Normalizes coordinates of this vector.

Returns

this


normalized()

normalized(): Vector2d

Returns new Vector2d object with normalized coordinates of this vector.

Returns

Vector2d


reverse()

reverse(): this

Reverses coordinates of this vector.

Returns

this


reversed()

reversed(): Vector2d

Returns new Vector2d object with coordinates received by performing a reverse() operation to this object.

Returns

Vector2d


setCoord()

setCoord(x?, y?): this

Sets x and y coordinates of this object.

Parameters

x?

number

X coordinate of 2D vector.

y?

number

Y coordinate of 2D vector.

Returns

this


setX()

setX(x): this

Sets x coordinate of 2D vector.

Parameters

x

number

X coordinate.

Returns

this


setY()

setY(y): this

Sets y coordinate of 2D vector.

Parameters

y

number

Y coordinate.

Returns

this


subtract()

subtract(other): this

Subtracts other vector coordinates from this vector coordinates.

Parameters

other

Vector2d

Other vector.

Returns

this


subtracted()

subtracted(other): Vector2d

Returns new Vector2d object with coordinates received by performing a subtract() operation to this object.

Parameters

other

Vector2d

Other vector.

Returns

Vector2d


toJSON()

toJSON(): BaseXY

Returns JSON representation of this vector.

Returns

BaseXY


toString()

toString(precision): string

Returns string representation of this vector with provided precision (3 by default).

Parameters

precision

number = 3

Precision.

Returns

string


transform()

transform(transformation): this

Transforms coordinates of this vector according to transformation.

Parameters

transformation

Transformation2d

Transformation.

Returns

this


transformed()

transformed(transformation): Vector2d

Returns new Vector2d object with coordinates received by performing a transform() operation to this object.

Parameters

transformation

Transformation2d

Transformation.

Returns

Vector2d


fromPoints()

static fromPoints(start, end): Vector2d

Creates new Vector2d object from two points that represents start and end points of the vector.

Parameters

start

Point2d

Start point.

end

Point2d

End point.

Returns

Vector2d


fromXY()

static fromXY(xy): Vector2d

Creates new Vector2d object from object implementing BaseXY interface.

Parameters

xy

BaseXY

Object implementing BaseXY interface.

Returns

Vector2d