Home Reference Source
import {Vector3} from 'math-ds'
public class | source

Vector3

A vector with three components.

Constructor Summary

Public Constructor
public

Constructs a new vector.

Member Summary

Public Members
public

The X component.

public

The Y component.

public

The Z component.

Method Summary

Public Methods
public

Adds a vector to this one.

public

Adds a scalar to this vector.

public

Adds a scaled vector to this one.

public

Sets this vector to the sum of two given vectors.

public

Computes the angle to the given vector.

public

Applies a matrix to this vector.

public

Applies a matrix to this vector.

public

Applies a normal matrix to this vector and normalizes it.

public

Applies a quaternion to this vector.

public

Ceils this vector.

public

clamp(min: Vector3, max: Vector3): Vector3

Clamps this vector.

public

Clones this vector.

public

Copies the values of another vector.

public

Calculates the cross product of this vector and the given one.

public

Sets this vector to the cross product of the given vectors.

public

Calculates the distance to a given vector.

public

Calculates the squared distance to a given vector.

public

Divides this vector by another vector.

public

Divides this vector by a given scalar.

public

Calculates the dot product with another vector.

public

Checks if this vector equals the given one.

public

Floors this vector.

public

fromArray(array: Number[], offset: Number): Vector3

Copies values from an array.

public

Calculates the length of this vector.

public

Calculates the squared length of this vector.

public

lerp(v: Vector3, alpha: Number): Vector3

Lerps towards the given vector.

public

Sets this vector to the lerp result of the given vectors.

public

Calculates the Manhattan distance to a given vector.

public

Calculates the Manhattan length of this vector.

public

Adopts the max value for each component of this vector and the given one.

public

Adopts the min value for each component of this vector and the given one.

public

Multiplies this vector with another vector.

public

Multiplies this vector with a given scalar.

public

Sets this vector to the product of two given vectors.

public

Negates this vector.

public

Normalizes this vector.

public

Randomizes the values of this vector

public

Reflects this vector.

public

Rounds this vector.

public

set(x: Number, y: Number, z: Number): Vector3

Sets the values of this vector

public

Sets the values of this vector based on a cylindrical description.

public

Sets the values of this vector based on cylindrical coordinates.

public

Copies the values of a matrix column.

public

Copies the values of a matrix column.

public

Extracts the position from a matrix.

public

Extracts the scale from a matrix.

public

Sets the values of this vector based on a spherical description.

public

Sets the values of this vector based on spherical coordinates.

public

Sets the length of this vector.

public

Subtracts a vector from this vector.

public

Subtracts a scalar from this vector.

public

Sets this vector to the difference between two given vectors.

public

toArray(array: Array, offset: Number): Number[]

Stores this vector in an array.

public

Applies a matrix to this direction vector.

Public Constructors

public constructor(x: Number, y: Number, z: Number) source

Constructs a new vector.

Params:

NameTypeAttributeDescription
x Number
  • optional
  • default: 0

The X component.

y Number
  • optional
  • default: 0

The Y component.

z Number
  • optional
  • default: 0

The Z component.

Public Members

public x: Number source

The X component.

public y: Number source

The Y component.

public z: Number source

The Z component.

Public Methods

public add(v: Vector3): Vector3 source

Adds a vector to this one.

Params:

NameTypeAttributeDescription
v Vector3

The vector to add.

Return:

Vector3

This vector.

public addScalar(s: Number): Vector3 source

Adds a scalar to this vector.

Params:

NameTypeAttributeDescription
s Number

The scalar to add.

Return:

Vector3

This vector.

public addScaledVector(v: Vector3, s: Number): Vector3 source

Adds a scaled vector to this one.

Params:

NameTypeAttributeDescription
v Vector3

The vector to scale and add.

s Number

A scalar.

Return:

Vector3

This vector.

public addVectors(a: Vector3, b: Vector3): Vector3 source

Sets this vector to the sum of two given vectors.

Params:

NameTypeAttributeDescription
a Vector3

A vector.

b Vector3

Another vector.

Return:

Vector3

This vector.

public angleTo(v: Vector3): Number source

Computes the angle to the given vector.

Params:

NameTypeAttributeDescription
v Vector3

A vector.

Return:

Number

The angle in radians.

public applyMatrix3(m: Matrix3): Vector3 source

Applies a matrix to this vector.

Params:

NameTypeAttributeDescription
m Matrix3

A matrix.

Return:

Vector3

This vector.

public applyMatrix4(m: Matrix4): Vector3 source

Applies a matrix to this vector.

Params:

NameTypeAttributeDescription
m Matrix4

A matrix.

Return:

Vector3

This vector.

public applyNormalMatrix(m: Matrix3): Vector3 source

Applies a normal matrix to this vector and normalizes it.

Params:

NameTypeAttributeDescription
m Matrix3

A normal matrix.

Return:

Vector3

This vector.

public applyQuaternion(q: Quaternion): Vector3 source

Applies a quaternion to this vector.

Params:

NameTypeAttributeDescription
q Quaternion

A quaternion.

Return:

Vector3

This vector.

public ceil(): Vector3 source

Ceils this vector.

Return:

Vector3

This vector.

public clamp(min: Vector3, max: Vector3): Vector3 source

Clamps this vector.

Params:

NameTypeAttributeDescription
min Vector3

The lower bounds. Assumed to be smaller than max.

max Vector3

The upper bounds. Assumed to be greater than min.

Return:

Vector3

This vector.

public clone(): Vector3 source

Clones this vector.

Return:

Vector3

A clone of this vector.

public copy(v: Vector3): Vector3 source

Copies the values of another vector.

Params:

NameTypeAttributeDescription
v Vector3

A vector.

Return:

Vector3

This vector.

public cross(v: Vector3): Vector3 source

Calculates the cross product of this vector and the given one.

Params:

NameTypeAttributeDescription
v Vector3

A vector.

Return:

Vector3

This vector.

public crossVectors(a: Vector3, b: Vector3): Vector3 source

Sets this vector to the cross product of the given vectors.

Params:

NameTypeAttributeDescription
a Vector3

A vector.

b Vector3

Another vector.

Return:

Vector3

This vector.

public distanceTo(v: Vector3): Number source

Calculates the distance to a given vector.

Params:

NameTypeAttributeDescription
v Vector3

A vector.

Return:

Number

The distance.

public distanceToSquared(v: Vector3): Number source

Calculates the squared distance to a given vector.

Params:

NameTypeAttributeDescription
v Vector3

A vector.

Return:

Number

The squared distance.

public divide(v: Vector3): Vector3 source

Divides this vector by another vector.

Params:

NameTypeAttributeDescription
v Vector3

A vector.

Return:

Vector3

This vector.

public divideScalar(s: Number): Vector3 source

Divides this vector by a given scalar.

Params:

NameTypeAttributeDescription
s Number

A scalar.

Return:

Vector3

This vector.

public dot(v: Vector3): Number source

Calculates the dot product with another vector.

Params:

NameTypeAttributeDescription
v Vector3

A vector.

Return:

Number

The dot product.

public equals(v: Vector3): Boolean source

Checks if this vector equals the given one.

Params:

NameTypeAttributeDescription
v Vector3

A vector.

Return:

Boolean

Whether this vector equals the given one.

public floor(): Vector3 source

Floors this vector.

Return:

Vector3

This vector.

public fromArray(array: Number[], offset: Number): Vector3 source

Copies values from an array.

Params:

NameTypeAttributeDescription
array Number[]

An array.

offset Number

An offset.

Return:

Vector3

This vector.

public length(): Number source

Calculates the length of this vector.

Return:

Number

The length.

public lengthSquared(): Number source

Calculates the squared length of this vector.

Return:

Number

The squared length.

public lerp(v: Vector3, alpha: Number): Vector3 source

Lerps towards the given vector.

Params:

NameTypeAttributeDescription
v Vector3

The target vector.

alpha Number

The lerp factor.

Return:

Vector3

This vector.

public lerpVectors(v1: Vector3, v2: Vector3, alpha: Number): Vector3 source

Sets this vector to the lerp result of the given vectors.

Params:

NameTypeAttributeDescription
v1 Vector3

A base vector.

v2 Vector3

The target vector.

alpha Number

The lerp factor.

Return:

Vector3

This vector.

public manhattanDistanceTo(v: Vector3): Number source

Calculates the Manhattan distance to a given vector.

Params:

NameTypeAttributeDescription
v Vector3

A vector.

Return:

Number

The distance.

public manhattanLength(): Number source

Calculates the Manhattan length of this vector.

Return:

Number

The length.

public max(v: Vector3): Vector3 source

Adopts the max value for each component of this vector and the given one.

Params:

NameTypeAttributeDescription
v Vector3

A vector.

Return:

Vector3

This vector.

public min(v: Vector3): Vector3 source

Adopts the min value for each component of this vector and the given one.

Params:

NameTypeAttributeDescription
v Vector3

A vector.

Return:

Vector3

This vector.

public multiply(v: Vector3): Vector3 source

Multiplies this vector with another vector.

Params:

NameTypeAttributeDescription
v Vector3

A vector.

Return:

Vector3

This vector.

public multiplyScalar(s: Number): Vector3 source

Multiplies this vector with a given scalar.

Params:

NameTypeAttributeDescription
s Number

A scalar.

Return:

Vector3

This vector.

public multiplyVectors(a: Vector3, b: Vector3): Vector3 source

Sets this vector to the product of two given vectors.

Params:

NameTypeAttributeDescription
a Vector3

A vector.

b Vector3

Another vector.

Return:

Vector3

This vector.

public negate(): Vector3 source

Negates this vector.

Return:

Vector3

This vector.

public normalize(): Vector3 source

Normalizes this vector.

Return:

Vector3

This vector.

public random(): Vector3 source

Randomizes the values of this vector

Return:

Vector3

This vector.

public reflect(n: Vector3): Vector3 source

Reflects this vector. The given plane normal is assumed to be normalized.

Params:

NameTypeAttributeDescription
n Vector3

A normal.

Return:

Vector3

This vector.

public round(): Vector3 source

Rounds this vector.

Return:

Vector3

This vector.

public set(x: Number, y: Number, z: Number): Vector3 source

Sets the values of this vector

Params:

NameTypeAttributeDescription
x Number

The X component.

y Number

The Y component.

z Number

The Z component.

Return:

Vector3

This vector.

public setFromCylindrical(c: Cylindrical): Vector3 source

Sets the values of this vector based on a cylindrical description.

Params:

NameTypeAttributeDescription
c Cylindrical

A cylindrical description.

Return:

Vector3

This vector.

public setFromCylindricalCoords(radius: Number, theta: Number, y: Number): Vector3 source

Sets the values of this vector based on cylindrical coordinates.

Params:

NameTypeAttributeDescription
radius Number

The radius.

theta Number

Theta.

y Number

The height.

Return:

Vector3

This vector.

public setFromMatrix3Column(m: Matrix4, index: Number): Vector3 source

Copies the values of a matrix column.

Params:

NameTypeAttributeDescription
m Matrix4

A 3x3 matrix.

index Number

A column index of the range [0, 2].

Return:

Vector3

This vector.

public setFromMatrixColumn(m: Matrix4, index: Number): Vector3 source

Copies the values of a matrix column.

Params:

NameTypeAttributeDescription
m Matrix4

A 4x4 matrix.

index Number

A column index of the range [0, 3].

Return:

Vector3

This vector.

public setFromMatrixPosition(m: Matrix4): Vector3 source

Extracts the position from a matrix.

Params:

NameTypeAttributeDescription
m Matrix4

A 4x4 matrix.

Return:

Vector3

This vector.

public setFromMatrixScale(m: Matrix4): Vector3 source

Extracts the scale from a matrix.

Params:

NameTypeAttributeDescription
m Matrix4

A 4x4 matrix.

Return:

Vector3

This vector.

public setFromSpherical(s: Spherical): Vector3 source

Sets the values of this vector based on a spherical description.

Params:

NameTypeAttributeDescription
s Spherical

A spherical description.

Return:

Vector3

This vector.

public setFromSphericalCoords(radius: Number, phi: Number, theta: Number): Vector3 source

Sets the values of this vector based on spherical coordinates.

Params:

NameTypeAttributeDescription
radius Number

The radius.

phi Number

The polar angle.

theta Number

The angle around the equator of the sphere.

Return:

Vector3

This vector.

public setLength(length: Number): Vector3 source

Sets the length of this vector.

Params:

NameTypeAttributeDescription
length Number

The new length.

Return:

Vector3

This vector.

public sub(v: Vector3): Vector3 source

Subtracts a vector from this vector.

Params:

NameTypeAttributeDescription
v Vector3

The vector to subtract.

Return:

Vector3

This vector.

public subScalar(s: Number): Vector3 source

Subtracts a scalar from this vector.

Params:

NameTypeAttributeDescription
s Number

The scalar to subtract.

Return:

Vector3

This vector.

public subVectors(a: Vector3, b: Vector3): Vector3 source

Sets this vector to the difference between two given vectors.

Params:

NameTypeAttributeDescription
a Vector3

A vector.

b Vector3

A second vector.

Return:

Vector3

This vector.

public toArray(array: Array, offset: Number): Number[] source

Stores this vector in an array.

Params:

NameTypeAttributeDescription
array Array
  • optional

A target array.

offset Number

An offset.

Return:

Number[]

The array.

public transformDirection(m: Matrix4): Vector3 source

Applies a matrix to this direction vector.

Params:

NameTypeAttributeDescription
m Matrix4

A matrix.

Return:

Vector3

This vector.