Vector

Home

A Vector is an object used to represent a point in 3D space with three components: X, Y, Z.

Constructors

Vector( ): Vector Initializes with 0's for x, y, and z components.
Vector( x: number, y: number, z: number ): Vector Initializes with the given values.

Constants

X_AXIS = 0 Value is not explicit. Commonly used to represent the X-axis.
Y_AXIS = 1 Value is not explicit. Commonly used to represent the Y-axis.
Z_AXIS = 2 Value is not explicit. Commonly used to represent the Z-axis.

Variables

Public Variables

x: number The position of the vector along the X-axis.
y: number The position of the vector along the Y-axis.
z: number The position of the vector along the Z-axis.

Functions

Public Functions

add(a: number | Vector): Vector Adds a number or Vector to the current vector and returns this. If the given value is a number, it is added to all components of the current Vector.
addX(a: number): Vector Adds the number to the X value of the current vector. Returns this.
addY(a: number): Vector Adds the number to the Y value of the current vector. Returns this.
addZ(a: number): Vector Adds the number to the Z value of the current vector. Returns this.
angleBetween(v: Vector): number Returns the angle in radians between the current vector and given vector. Range: [0, PI].
closest(V: Array<Vector>): Vector Returns the vector in the given array that is the smallest distance from the current vector.
copy(): Vector Returns a copy of the current vector.
cross(v: Vector): Vector Applies the cross product of the current vector by the given vector and returns this.
div(a: number | Vector): Vector Divides a number or Vector from the current Vector and returns this. If the value is a number, it is divided from all components of the current vector. Prints an error if the given number is zero or if any components of the given Vector are zero.
divX(a: number): Vector Divides the number from the X value of the current vector. Returns this. Prints an error if the given number is zero.
divY(a: number): Vector Divides the number from the Y value of the current vector. Returns this. Prints an error if the given number is zero.
divZ(a: number): Vector Divides the number from the Z value of the current vector. Returns this. Prints an error if the given number is zero.
dot(v: Vector): number Returns the dot product of the current vector and given vector.
equals(v: Vector): boolean Returns true if the current vector has the same X, Y, Z components as the given vector.
furthest(V: Array<Vector>): Vector Returns the vector in the given array that is the largest distance from the current vector.
mag(): number Returns the magnitude of the current vector.
mult(a: number | Vector) Multiplies the current Vector by a number or Vector and returns this. If the value is a number, it is multiplied to all components of the current vector.
multX(a: number) Multiplies the X component of the current Vector by a number and returns this.
multY(a: number) Multiplies the Y component of the current Vector by a number and returns this.
multZ(a: number) Multiplies the Z component of the current Vector by a number and returns this.
neg(): Vector Negates all components of the current vector and returns this.
normalize(): Vector Normalizes the current vector so that its magnitude is 1. Returns this.
qRotate(q: Quaternion): Vector Shorthand for quaternionRotate()
quaternionRotate(q: Quaternion): Vector Applies the given quaternion rotation to the current vector and returns this. See also: Quaternion
rotateAxis(axis: number | Vector, angle: number): Vector Rotates the current vector around the given axis by the angle in radians and returns this. One of the following number constants can also be given as the axis: (Vector.X_AXIS, Vector.Y_AXIS, Vector.Z_AXIS).
rotateX(xAngle: number): Vector Rotates the current vector around the X-axis by the given angle in radians and returns this.
rotateY(yAngle: number): Vector Rotates the current vector around the Y-axis by the given angle in radians and returns this.
rotateZ(zAngle: number): Vector Rotates the current vector around the Z-axis by the given angle in radians and returns this.
sub(a: number | Vector): Vector Subtracts a number or Vector from the current Vector and returns this. If the value is a number, it is subtracted from all components of the current vector.
subX(a: number): Vector Subtracts the number from the X value of the current vector. Returns this.
subY(a: number): Vector Subtracts the number from the Y value of the current vector. Returns this.
subZ(a: number): Vector Subtracts the number from the Z value of the current vector. Returns this.
transform(M: Array<Array<number>>): Vector Applies the given 3 or 4 dimensional matrix transformation to the current vector and returns this.

Static Functions

Vector.add(v: Vector, a: number | Vector): Vector Returns the addition of a number or Vector to a copy of the given vector.
Vector.addX(v: Vector, a: number): Vector Returns the addition of a number to the X component of a copy of the given vector.
Vector.addY(v: Vector, a: number): Vector Returns the addition of a number to the Y component of a copy of the given vector.
Vector.addZ(v: Vector, a: number): Vector Returns the addition of a number to the Z component of a copy of the given vector.
Vector.angleBetween(v0: Vector, v1: Vector): number Returns the angle in radians between the two given vectors. Range: [0, PI].
Vector.axis(a: number): Vector Returns the corresponding unit vector that represents the given axis constant. Any of the following are acceptable values for the axis number: (Vector.X_AXIS, Vector.Y_AXIS, Vector.Z_AXIS).
Vector.closest(v: Vector, V: Array<Vector>): Vector Returns the vector in the given array of vectors that has the smallest distance from the given vector.
Vector.copy(v: Vector | {x: number, y: number, z: number}): Vector Returns a copy of the given vector or creates a vector from an object with x, y, z properties.
Vector.cross(v0: Vector, v1: Vector): Vector Returns the cross product of a copy of the first given vector by the second given vector.
Vector.div(v: Vector, a: number | Vector): Vector Returns the division of a number or Vector from a copy of the given vector.
Vector.divX(v: Vector, a: number): Vector Returns the division of a number from the X component of a copy of the given vector.
Vector.divY(v: Vector, a: number): Vector Returns the division of a number from the Y component of a copy of the given vector.
Vector.divZ(v: Vector, a: number): Vector Returns the division of a number from the Z component of a copy of the given vector.
Vector.dot(v0: Vector, v1: Vector): number Returns the dot product of the two given vectors.
Vector.equals(v0: Vector, v1: Vector): boolean Returns true if the two vectors have the same X, Y, Z components.
Vector.furthest(v: Vector, V: Array<Vector>): Vector Returns the vector in the given array of vectors that has the largest distance from the given vector.
Vector.mag(v: Vector): number Returns the magnitude of the given vector.
Vector.mult(v: Vector, a: number | Vector): Vector Returns the multiplication of a number or Vector by a copy of the given vector.
Vector.multX(v: Vector, a: number): Vector Returns the multiplication of a number by the X component of a copy of the given vector.
Vector.multY(v: Vector, a: number): Vector Returns the multiplication of a number by the Y component of a copy of the given vector.
Vector.multZ(v: Vector, a: number): Vector Returns the multiplication of a number by the Z component of a copy of the given vector.
Vector.neg(v: Vector): Vector Returns the negation of a copy of the given vector.
Vector.normalize(v: Vector): Vector Returns a normalized copy of the given vector.
Vector.qRotate(v: Vector, q: Quaternion): Vector Shorthand for Vector.quaternionRotate()
Vector.quaternionRotate(v: Vector, q: Quaternion): Vector Returns a copy of the given vector rotated by the given quaternion. See also: Quaternion
Vector.rotateAxis(v: Vector, axis: number | Vector, angle: number): Vector Returns a copy of the given vector rotated by the given angle around the given axis. One of the following number constants can also be given as the axis: (Vector.X_AXIS, Vector.Y_AXIS, Vector.Z_AXIS).
Vector.rotateX(v: Vector, xAngle: number): Vector Returns a copy of the given vector rotated around the X-axis by the given angle.
Vector.rotateY(v: Vector, xAngle: number): Vector Returns a copy of the given vector rotated around the Y-axis by the given angle.
Vector.rotateZ(v: Vector, xAngle: number): Vector Returns a copy of the given vector rotated around the Z-axis by the given angle.
Vector.sub(v: Vector, a: number | Vector): Vector Returns the subtraction of a number or Vector from a copy of the given vector.
Vector.subX(v: Vector, a: number): Vector Returns the subtraction of a number from the X component of a copy of the given vector.
Vector.subY(v: Vector, a: number): Vector Returns the subtraction of a number from the Y component of a copy of the given vector.
Vector.subZ(v: Vector, a: number): Vector Returns the subtraction of a number from the Z component of a copy of the given vector.
Vector.transform(v: Vector, M: Array<Array<number>>): Vector Returns the transformation of a copy of the given vector by the given 3 or 4 dimensional Matrix.
Vector.xAxis(): Vector Returns the unit vector that lies upon the X-axis.
Vector.yAxis(): Vector Returns the unit vector that lies upon the Y-axis.
Vector.zAxis(): Vector Returns the unit vector that lies upon the Z-axis.

Home

Copyright © 2020 Trevor Richard