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

Vector4

A vector with four components.

Constructor Summary

Public Constructor
public

Constructs a new vector.

Member Summary

Public Members
public

The W component.

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

Applies a matrix to this vector.

public

Ceils this vector.

public

clamp(min: Vector4, max: Vector4): Vector4

Clamps this vector.

public

Clones this vector.

public

Copies the values of another vector.

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): Vector4

Copies values from an array.

public

Calculates the length of this vector.

public

Calculates the squared length of this vector.

public

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

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

Rounds this vector.

public

set(x: Number, y: Number, z: Number, w: Number): Vector4

Sets the values of this vector

public

Stores the axis angle from the given quaternion in this vector.

public

Stores the axis angle from the given rotation matrix in this vector.

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 Constructors

public constructor(x: Number, y: Number, z: Number, w: 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.

w Number
  • optional
  • default: 0

The W component.

Public Members

public w: Number source

The W component.

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: Vector4): Vector4 source

Adds a vector to this one.

Params:

NameTypeAttributeDescription
v Vector4

The vector to add.

Return:

Vector4

This vector.

public addScalar(s: Number): Vector4 source

Adds a scalar to this vector.

Params:

NameTypeAttributeDescription
s Number

The scalar to add.

Return:

Vector4

This vector.

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

Adds a scaled vector to this one.

Params:

NameTypeAttributeDescription
v Vector4

The vector to scale and add.

s Number

A scalar.

Return:

Vector4

This vector.

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

Sets this vector to the sum of two given vectors.

Params:

NameTypeAttributeDescription
a Vector4

A vector.

b Vector4

Another vector.

Return:

Vector4

This vector.

public applyMatrix4(m: Matrix4): Vector4 source

Applies a matrix to this vector.

Params:

NameTypeAttributeDescription
m Matrix4

A matrix.

Return:

Vector4

This vector.

public ceil(): Vector4 source

Ceils this vector.

Return:

Vector4

This vector.

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

Clamps this vector.

Params:

NameTypeAttributeDescription
min Vector4

The lower bounds. Assumed to be smaller than max.

max Vector4

The upper bounds. Assumed to be greater than min.

Return:

Vector4

This vector.

public clone(): Vector4 source

Clones this vector.

Return:

Vector4

A clone of this vector.

public copy(v: Vector4): Vector4 source

Copies the values of another vector.

Params:

NameTypeAttributeDescription
v Vector4

A vector.

Return:

Vector4

This vector.

public distanceTo(v: Vector4): Number source

Calculates the distance to a given vector.

Params:

NameTypeAttributeDescription
v Vector4

A vector.

Return:

Number

The distance.

public distanceToSquared(v: Vector4): Number source

Calculates the squared distance to a given vector.

Params:

NameTypeAttributeDescription
v Vector4

A vector.

Return:

Number

The squared distance.

public divide(v: Vector4): Vector4 source

Divides this vector by another vector.

Params:

NameTypeAttributeDescription
v Vector4

A vector.

Return:

Vector4

This vector.

public divideScalar(s: Number): Vector4 source

Divides this vector by a given scalar.

Params:

NameTypeAttributeDescription
s Number

A scalar.

Return:

Vector4

This vector.

public dot(v: Vector4): Number source

Calculates the dot product with another vector.

Params:

NameTypeAttributeDescription
v Vector4

A vector.

Return:

Number

The dot product.

public equals(v: Vector4): Boolean source

Checks if this vector equals the given one.

Params:

NameTypeAttributeDescription
v Vector4

A vector.

Return:

Boolean

Whether this vector equals the given one.

public floor(): Vector4 source

Floors this vector.

Return:

Vector4

This vector.

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

Copies values from an array.

Params:

NameTypeAttributeDescription
array Number[]

An array.

offset Number

An offset.

Return:

Vector4

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: Vector4, alpha: Number): Vector4 source

Lerps towards the given vector.

Params:

NameTypeAttributeDescription
v Vector4

The target vector.

alpha Number

The lerp factor.

Return:

Vector4

This vector.

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

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

Params:

NameTypeAttributeDescription
v1 Vector4

A base vector.

v2 Vector4

The target vector.

alpha Number

The lerp factor.

Return:

Vector4

This vector.

public manhattanDistanceTo(v: Vector4): Number source

Calculates the Manhattan distance to a given vector.

Params:

NameTypeAttributeDescription
v Vector4

A vector.

Return:

Number

The distance.

public manhattanLength(): Number source

Calculates the Manhattan length of this vector.

Return:

Number

The length.

public max(v: Vector4): Vector4 source

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

Params:

NameTypeAttributeDescription
v Vector4

A vector.

Return:

Vector4

This vector.

public min(v: Vector4): Vector4 source

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

Params:

NameTypeAttributeDescription
v Vector4

A vector.

Return:

Vector4

This vector.

public multiply(v: Vector4): Vector4 source

Multiplies this vector with another vector.

Params:

NameTypeAttributeDescription
v Vector4

A vector.

Return:

Vector4

This vector.

public multiplyScalar(s: Number): Vector4 source

Multiplies this vector with a given scalar.

Params:

NameTypeAttributeDescription
s Number

A scalar.

Return:

Vector4

This vector.

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

Sets this vector to the product of two given vectors.

Params:

NameTypeAttributeDescription
a Vector4

A vector.

b Vector4

Another vector.

Return:

Vector4

This vector.

public negate(): Vector4 source

Negates this vector.

Return:

Vector4

This vector.

public normalize(): Vector4 source

Normalizes this vector.

Return:

Vector4

This vector.

public random(): Vector4 source

Randomizes the values of this vector

Return:

Vector4

This vector.

public round(): Vector4 source

Rounds this vector.

Return:

Vector4

This vector.

public set(x: Number, y: Number, z: Number, w: Number): Vector4 source

Sets the values of this vector

Params:

NameTypeAttributeDescription
x Number

The X component.

y Number

The Y component.

z Number

The Z component.

w Number

The W component.

Return:

Vector4

This vector.

public setAxisAngleFromQuaternion(q: Quaternion): Vector4 source

Stores the axis angle from the given quaternion in this vector.

For more details see: http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm

Params:

NameTypeAttributeDescription
q Quaternion

A quaternion. Assumed to be normalized

Return:

Vector4

This vector.

public setAxisAngleFromRotationMatrix(m: Matrix4): Vector4 source

Stores the axis angle from the given rotation matrix in this vector.

For more details see: http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm

Params:

NameTypeAttributeDescription
m Matrix4

A matrix. The upper 3x3 must be a pure rotation matrix (i.e. unscaled).

Return:

Vector4

This vector.

public setLength(length: Number): Vector4 source

Sets the length of this vector.

Params:

NameTypeAttributeDescription
length Number

The new length.

Return:

Vector4

This vector.

public sub(v: Vector4): Vector4 source

Subtracts a vector from this vector.

Params:

NameTypeAttributeDescription
v Vector4

The vector to subtract.

Return:

Vector4

This vector.

public subScalar(s: Number): Vector4 source

Subtracts a scalar from this vector.

Params:

NameTypeAttributeDescription
s Number

The scalar to subtract.

Return:

Vector4

This vector.

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

Sets this vector to the difference between two given vectors.

Params:

NameTypeAttributeDescription
a Vector4

A vector.

b Vector4

A second vector.

Return:

Vector4

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.