Vector3(x, y, z)

Class representing a 3D vector.

new Vector3(x, y, z)

Constructs a new 3D vector with the given values.

Parameters:
Name Type Default Description
x Number 0

The x component.

y Number 0

The y component.

z Number 0

The z component.

Author:

Members

x :Number

The x component.

y :Number

The y component.

z :Number

The z component.

Methods

add(v) → {Vector3}

Adds the given 3D vector to this 3D vector.

Parameters:
Name Type Description
v Vector3

The vector to add.

Returns:
Vector3 -

A reference to this vector.

addScalar(s) → {Vector3}

Adds the given scalar to this 3D vector.

Parameters:
Name Type Description
s Number

The scalar to add.

Returns:
Vector3 -

A reference to this vector.

addVectors(a, b) → {Vector3}

Adds two given 3D vectors and stores the result in this 3D vector.

Parameters:
Name Type Description
a Vector3

The first vector of the operation.

b Vector3

The second vector of the operation.

Returns:
Vector3 -

A reference to this vector.

angleTo(v) → {Number}

Computes the angle between this and the given vector.

Parameters:
Name Type Description
v Vector3

A 3D vector.

Returns:
Number -

The angle in radians.

applyMatrix4(m) → {Vector3}

Multiplies the given 4x4 matrix with this 3D vector

Parameters:
Name Type Description
m Matrix4

A 4x4 matrix.

Returns:
Vector3 -

A reference to this vector.

applyRotation(q) → {Vector3}

Multiplies the given quaternion with this 3D vector.

Parameters:
Name Type Description
q Quaternion

A quaternion.

Returns:
Vector3 -

A reference to this vector.

clamp(min, max) → {Vector3}

Ensures this 3D vector lies in the given min/max range.

Parameters:
Name Type Description
min Vector3

The min range.

max Vector3

The max range.

Returns:
Vector3 -

A reference to this vector.

clone() → {Vector3}

Creates a new 3D vector and copies all values from this 3D vector.

Returns:
Vector3 -

A new 3D vector.

copy(v) → {Vector3}

Copies all values from the given 3D vector to this 3D vector.

Parameters:
Name Type Description
v Vector3

The vector to copy.

Returns:
Vector3 -

A reference to this vector.

cross(v) → {Vector3}

Computes the cross product of this and the given 3D vector and stores the result in this 3D vector.

Parameters:
Name Type Description
v Vector3

A 3D vector.

Returns:
Vector3 -

A reference to this vector.

crossVectors(a, b) → {Vector3}

Computes the cross product of the two given 3D vectors and stores the result in this 3D vector.

Parameters:
Name Type Description
a Vector3

The first 3D vector.

b Vector3

The second 3D vector.

Returns:
Vector3 -

A reference to this vector.

distanceTo(v) → {Number}

Computes the euclidean distance between this 3D vector and the given one.

Parameters:
Name Type Description
v Vector3

A 3D vector.

Returns:
Number -

The euclidean distance between two 3D vectors.

divide(v) → {Vector3}

Divides the given 3D vector through this 3D vector.

Parameters:
Name Type Description
v Vector3

The vector to divide.

Returns:
Vector3 -

A reference to this vector.

divideScalar(s) → {Vector3}

Divides the given scalar through this 3D vector.

Parameters:
Name Type Description
s Number

The scalar to multiply.

Returns:
Vector3 -

A reference to this vector.

divideVectors(a, b) → {Vector3}

Divides two given 3D vectors and stores the result in this 3D vector.

Parameters:
Name Type Description
a Vector3

The first vector of the operation.

b Vector3

The second vector of the operation.

Returns:
Vector3 -

A reference to this vector.

dot(v) → {Number}

Computes the dot product of this and the given 3D vector.

Parameters:
Name Type Description
v Vector3

The given 3D vector.

Returns:
Number -

The results of the dor product.

equals(v) → {Boolean}

Returns true if the given 3D vector is deep equal with this 3D vector.

Parameters:
Name Type Description
v Vector3

The 3D vector to test.

Returns:
Boolean -

The result of the equality test.

extractPositionFromMatrix(m) → {Vector3}

Extracts the position portion of the given 4x4 matrix and stores it in this 3D vector.

Parameters:
Name Type Description
m Matrix4

A 4x4 matrix.

Returns:
Vector3 -

A reference to this vector.

fromArray(array, offset) → {Vector3}

Sets the components of this 3D vector from an array.

Parameters:
Name Type Default Description
array Array.<Number>

An array.

offset Number 0

An optional offset.

Returns:
Vector3 -

A reference to this vector.

fromMatrix3Column(m, i) → {Vector3}

Sets the components of this 3D vector from a column of a 3x3 matrix.

Parameters:
Name Type Description
m Matrix3

A 3x3 matrix.

i Number

The index of the column.

Returns:
Vector3 -

A reference to this vector.

fromMatrix4Column(m, i) → {Vector3}

Sets the components of this 3D vector from a column of a 4x4 matrix.

Parameters:
Name Type Description
m Matrix3

A 4x4 matrix.

i Number

The index of the column.

Returns:
Vector3 -

A reference to this vector.

fromSpherical(radius, phi, theta) → {Vector3}

Sets the components of this 3D vector from a spherical coordinate.

Parameters:
Name Type Description
radius Number

The radius.

phi Number

The polar or inclination angle in radians. Should be in the range of (−π/2, +π/2].

theta Number

The azimuthal angle in radians. Should be in the range of (−π, +π].

Returns:
Vector3 -

A reference to this vector.

length() → {Number}

Computes the length of this 3D vector.

Returns:
Number -

The length of this 3D vector.

manhattanDistanceTo(v) → {Number}

Computes the manhattan distance between this 3D vector and the given one.

Parameters:
Name Type Description
v Vector3

A 3D vector.

Returns:
Number -

The manhattan distance between two 3D vectors.

manhattanLength() → {Number}

Computes the manhattan length of this 3D vector.

Returns:
Number -

The manhattan length of this 3D vector.

max(v) → {Vector3}

Compares each vector component of this 3D vector and the given one and stores the maximum value in this instance.

Parameters:
Name Type Description
v Vector3

The 3D vector to check.

Returns:
Vector3 -

A reference to this vector.

min(v) → {Vector3}

Compares each vector component of this 3D vector and the given one and stores the minimum value in this instance.

Parameters:
Name Type Description
v Vector3

The 3D vector to check.

Returns:
Vector3 -

A reference to this vector.

multiply(v) → {Vector3}

Multiplies the given 3D vector with this 3D vector.

Parameters:
Name Type Description
v Vector3

The vector to multiply.

Returns:
Vector3 -

A reference to this vector.

multiplyScalar(s) → {Vector3}

Multiplies the given scalar with this 3D vector.

Parameters:
Name Type Description
s Number

The scalar to multiply.

Returns:
Vector3 -

A reference to this vector.

multiplyVectors(a, b) → {Vector3}

Multiplies two given 3D vectors and stores the result in this 3D vector.

Parameters:
Name Type Description
a Vector3

The first vector of the operation.

b Vector3

The second vector of the operation.

Returns:
Vector3 -

A reference to this vector.

normalize() → {Vector3}

Normalizes this 3D vector.

Returns:
Vector3 -

A reference to this vector.

reflect(normal) → {Vector3}

Reflects this vector along the given normal.

Parameters:
Name Type Description
normal Vector3

The normal vector.

Returns:
Vector3 -

A reference to this vector.

set(x, y, z) → {Vector3}

Sets the given values to this 3D vector.

Parameters:
Name Type Description
x Number

The x component.

y Number

The y component.

z Number

The z component.

Returns:
Vector3 -

A reference to this vector.

squaredDistanceTo(v) → {Number}

Computes the squared euclidean distance between this 3D vector and the given one. Calling this method is faster than calling Vector3#distanceTo, since it avoids computing a square root.

Parameters:
Name Type Description
v Vector3

A 3D vector.

Returns:
Number -

The squared euclidean distance between two 3D vectors.

squaredLength() → {Number}

Computes the squared length of this 3D vector. Calling this method is faster than calling Vector3#length, since it avoids computing a square root.

Returns:
Number -

The squared length of this 3D vector.

sub(v) → {Vector3}

Subtracts the given 3D vector from this 3D vector.

Parameters:
Name Type Description
v Vector3

The vector to substract.

Returns:
Vector3 -

A reference to this vector.

subScalar(s) → {Vector3}

Subtracts the given scalar from this 3D vector.

Parameters:
Name Type Description
s Number

The scalar to substract.

Returns:
Vector3 -

A reference to this vector.

subVectors(a, b) → {Vector3}

Subtracts two given 3D vectors and stores the result in this 3D vector.

Parameters:
Name Type Description
a Vector3

The first vector of the operation.

b Vector3

The second vector of the operation.

Returns:
Vector3 -

A reference to this vector.

toArray(array, offset) → {Array.<Number>}

Copies all values of this 3D vector to the given array.

Parameters:
Name Type Default Description
array Array.<Number>

An array.

offset Number 0

An optional offset.

Returns:
Array.<Number> -

The array with the 3D vector components.

transformDirection(m) → {Vector3}

Transform this direction vector by the given 4x4 matrix.

Parameters:
Name Type Description
m Matrix4

A 4x4 matrix.

Returns:
Vector3 -

A reference to this vector.