Class: Vector

Vector

new Vector(arrayOrNumber)

General vector type.
Parameters:
Name Type Description
arrayOrNumber Array | number An array whose entries will become the values of the vector. The vector's dimension will be set to the array's length -or- a number that will set the Vector's value. Each of the Vector's entries will be set to zero.
Source:

Extends

Methods

(static) copy(vector, outopt) → {Vector}

Parameters:
Name Type Attributes Description
vector Vector The Vector to copy from.
out Vector <optional>
The Vector to copy to. If undefined, a new Vector is created.
Source:
Returns:
The out vector.
Type
Vector

(static) cross(vec1, vec2, outopt) → {Vector}

Parameters:
Name Type Attributes Description
vec1 Vector The first Vector.
vec2 Vector The second Vector.
out Vector <optional>
The Vector that will contain the result of the cross product of the two Vectors. If undefined, a new Vector is created.
Source:
Throws:
if vec1 and vec2 are not 3-dimensional Vectors.
Type
DimensionError
Returns:
The out Vector.
Type
Vector

(static) dot(vec1, vec2) → {number}

Parameters:
Name Type Description
vec1 Vector The first Vector.
vec2 Vector The second Vector.
Source:
Throws:
if the dimension of vec1 and vec2 are not equal.
Type
DimensionError
Returns:
The dot product of the two Vectors.
Type
number

(static) flatten(arrayOfVectors, arrayTypeopt) → {Array|TypedArray}

Parameters:
Name Type Attributes Default Description
arrayOfVectors Array An array of Vectors.
arrayType constructor <optional>
Float32Array The type of Array to create. This method can create typed arrays.
Source:
Returns:
a new Array or TypedArray who will be filled with the values of the Vectors.
Type
Array | TypedArray

(static) quadrance(vec1, vec2) → {number}

Parameters:
Name Type Description
vec1 Vector The first Vector.
vec2 Vector The second Vector.
Source:
Throws:
if the dimension of vec1 and vec2 are not equal.
Type
DimensionError
Returns:
The quadrance of the two Vectors.
Type
number

add(vec) → {Vector}

Adds each entry of vec to the corresponding entries of this Vector.
Parameters:
Name Type Description
vec Vector The Vector
Source:
Throws:
if the dimension of this Vector and vec are not equal.
Type
DimensionError
Returns:
This Vector.
Type
Vector

dot(vec) → {number}

Parameters:
Name Type Description
vec Vector The Vector.
Source:
Returns:
The dot product of this Vector and vec
Type
number

equals(array) → {boolean}

Parameters:
Name Type Description
array Array The array to compare this Dimensional to.
Inherited From:
Source:
Returns:
True if all entries are equal, false otherwise.
Type
boolean

magnitude() → {number}

Source:
Returns:
The magnitude (length) of this Vector.
Type
number

normalize() → {Vector}

Normalizes this Vector.
Source:
Returns:
This Vector.
Type
Vector

quadrance(vec) → {number}

Parameters:
Name Type Description
vec Vector The Vector.
Source:
Returns:
The quadrance of this Vector and vector.
Type
number

scale(scalar) → {Vector}

Scales each entry of this Vector by scalar.
Parameters:
Name Type Description
scalar number The scalar.
Source:
Throws:
if scalar is not of type number.
Type
TypeError
Returns:
This Vector.
Type
Vector

set(array) → {Vector}

Parameters:
Name Type Description
array array The array.
Source:
Throws:
if the dimension of this Vector and array are not equal.
Type
DimensionError
Returns:
this Vector
Type
Vector

set^2(…varargs) → {Vector}

Parameters:
Name Type Attributes Description
varargs number <repeatable>
Numbers this Vectors entries will be set from.
Source:
Throws:
if the dimension of this Vector and the number of varargs are not equal.
Type
DimensionError
Returns:
This Vector.
Type
Vector

toArray() → {Array}

This handles some edge cases such as Array.concat in which a subtype of Array is not considered an Array.
Source:
Returns:
An Array whose entries are set from this Vector.
Type
Array

toString() → {string}

Source:
Returns:
A string representation of this Vector.
Type
string

zero() → {Vector}

Set the value of every entry of this Vector to 0.
Source:
Returns:
This Vector.
Type
Vector