Hide menu
Loading...
Searching...
No Matches
Vector

Defines vector in 3D space.

Constructors

new Vector()

new Vector(x?, y?, z?): Vector

Parameters

x?

number

X coordinate of 3D vector.

y?

number

Y coordinate of 3D vector.

z?

number

Z coordinate of 3D vector.

Returns

Vector

Accessors

x

Get Signature

get x(): number

Returns x coordinate of 3D vector.

Returns

number

Set Signature

set x(x): void

Sets x coordinate of 3D vector.

Parameters

x

number

X coordinate.

Returns

void


y

Get Signature

get y(): number

Returns y coordinate of 3D vector.

Returns

number

Set Signature

set y(y): void

Sets y coordinate of 3D vector.

Parameters

y

number

Y coordinate.

Returns

void


z

Get Signature

get z(): number

Returns z coordinate of 3D vector.

Returns

number

Set Signature

set z(z): void

Sets z coordinate of 3D vector.

Parameters

z

number

Z coordinate.

Returns

void

Methods

add()

add(other): this

Adds other vector coordinates to this vector coordinates.

Parameters

other

Vector

Other vector.

Returns

this


added()

added(other): Vector

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

Parameters

other

Vector

Other vector.

Returns

Vector


angle()

angle(other): number

Returns angle between this and other vectors.

Parameters

other

Vector

Other vector.

Returns

number


clone()

clone(): Vector

Creates new Vector object with coordinates same as this.

Returns

Vector


copy()

copy(other): this

Copies the coordinates of the other vector to this.

Parameters

other

Vector

Copied object.

Returns

this


cross()

cross(other): this

Sets coordinates of this vector as cross product of this and other vectors.

Parameters

other

Vector

Other vector.

Returns

this


crossed()

crossed(other): Vector

Returns new Vector object with coordinates received by performing a cross() operation to this object.

Parameters

other

Vector

Other vector.

Returns

Vector


divide()

divide(scalar): this

Divide this vector coordinates by scalar value.

Parameters

scalar

number

Scalar value.

Returns

this


divided()

divided(scalar): Vector

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

Parameters

scalar

number

Scalar value.

Returns

Vector


dot()

dot(other): number

Returns dot product of this and other vector.

Parameters

other

Vector

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

Vector

Other 3D 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

Vector

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

Vector

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

Vector

Other vector.

tolerance?

number

Returns

boolean


length()

length(): number

Returns length of the vector.

Returns

number


mirror()

Call Signature

mirror(direction): this

Mirrors this 3D vector relative to direction.

Parameters

direction

Direction

Direction.

Returns

this

Call Signature

mirror(axis): this

Mirrors this 3D vector relative to axis.

Parameters

axis

Axis1d

Axis.

Returns

this

Call Signature

mirror(axis): this

Mirrors this 3D vector relative to axis.

Parameters

axis

Axis3d

Axis.

Returns

this


mirrored()

Call Signature

mirrored(direction): Vector

Returns new Vector object with coordinates received by performing a mirror() operation to this object.

Parameters

direction

Direction

Direction.

Returns

Vector

Call Signature

mirrored(axis): Vector

Returns new Vector object with coordinates received by performing a mirror() operation to this object.

Parameters

axis

Axis1d

Axis.

Returns

Vector

Call Signature

mirrored(axis): Vector

Returns new Vector object with coordinates received by performing a mirror() operation to this object.

Parameters

axis

Axis3d

Axis.

Returns

Vector


multiplied()

Call Signature

multiplied(other): Vector

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

Parameters

other

Vector

Other vector.

Returns

Vector

Call Signature

multiplied(matrix): Vector

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

Parameters

matrix

Matrix3d

3D matrix.

Returns

Vector

Call Signature

multiplied(scalar): Vector

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

Parameters

scalar

number

Scalar value.

Returns

Vector


multiply()

Call Signature

multiply(other): this

Multiplies this vector coordinates with other vector coordinates.

Parameters

other

Vector

Other vector.

Returns

this

Call Signature

multiply(matrix): this

Multiplies this point coordinates with 3D matrix.

Parameters

matrix

Matrix3d

3D 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(): Vector

Returns new Vector object with normalized coordinates of this vector.

Returns

Vector


reverse()

reverse(): this

Reverses coordinates of this vector.

Returns

this


reversed()

reversed(): Vector

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

Returns

Vector


rotate()

rotate(axis, angle): this

Rotates this 3D vector around axis on angle.

Parameters

axis

Axis1d

Rotation axis.

angle

number

Rotation angle.

Returns

this


rotated()

rotated(axis, angle): Vector

Returns new Vector object with coordinates received by performing a rotate() operation to this object.

Parameters

axis

Axis1d

Rotation axis.

angle

number

Rotation angle.

Returns

Vector


setCoord()

setCoord(x?, y?, z?): this

Sets x,y and z coordinates of this object.

Parameters

x?

number

X coordinate of 3D vector.

y?

number

Y coordinate of 3D vector.

z?

number

Z coordinate of 3D vector.

Returns

this


setX()

setX(x): this

Sets x coordinate of 3D vector.

Parameters

x

number

X coordinate.

Returns

this


setY()

setY(y): this

Sets y coordinate of 3D vector.

Parameters

y

number

Y coordinate.

Returns

this


setZ()

setZ(z): this

Sets z coordinate of 3D vector.

Parameters

z

number

Z coordinate.

Returns

this


subtract()

subtract(other): this

Subtracts other vector coordinates from this vector coordinates.

Parameters

other

Vector

Other vector.

Returns

this


subtracted()

subtracted(other): Vector

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

Parameters

other

Vector

Other vector.

Returns

Vector


toJSON()

toJSON(): BaseXYZ

Returns JSON representation of this vector.

Returns

BaseXYZ


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

Transformation

Transformation.

Returns

this


transformed()

transformed(transformation): Vector

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

Parameters

transformation

Transformation

Transformation.

Returns

Vector


fromPoints()

static fromPoints(start, end): Vector

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

Parameters

start

Point

Start point.

end

Point

End point.

Returns

Vector


fromXYZ()

static fromXYZ(xyz): Vector

Creates new Vector object from object implementing BaseXYZ interface.

Parameters

xyz

BaseXYZ

Object implementing BaseXYZ interface.

Returns

Vector