Vector
Extends:
Simple extension to js Array to allow function chaining when doing vector operations. A vector instance can be used the same way as a native Array instance. Note that length will therefore return the number of vector components, and not its scalar value. Use the scalar function if you want to know the vector's length.
Instantiate a vector by its constructor or using one of the factory functions (vec2, vec3...)
Static Method Summary
Static Public Methods | ||
public static |
Instantiate a vector from an array. |
Member Summary
Public Members | ||
public |
[i]: * assign value |
Method Summary
Public Methods | ||
public |
Add one or more vectors to this vector |
|
public |
Add a scaled version of a vector to this vector |
|
public |
Clone/copy vector |
|
public |
Find the cross product vector between this vector and the passed in argument. |
|
public |
Calculate the psudo cross product between this vector and the passed in argument. |
|
public |
Calculate the distance between this coordinates to the coordinates supplied in the argument |
|
public |
Calculate the dot product between this vector and the passed in argument |
|
public |
Test if this vector is a null vector |
|
public |
Negate all components of this vector |
|
public |
Normalize this vector |
|
public |
Calculate the scalar product (length) of this vector. |
|
public |
Scale this vector by a factor |
|
public |
Assign values to this vector |
|
public |
Subtract one or more vectors from this vector |
|
public |
Subtract a scaled version of a vector from this vector |
|
public |
Mimic the swizzle feature in glsl. |
Static Public Methods
Public Members
Public Methods
public add(vectors: ...number[]): Vector source
Add one or more vectors to this vector
Params:
Name | Type | Attribute | Description |
vectors | ...number[] | vectors to add to this |
public addScaled(vector: number[], factor: number): Vector source
Add a scaled version of a vector to this vector
public cross(other: number[], target: Array/Vector): Vector source
Find the cross product vector between this vector and the passed in argument. Only for 3d vectors!
Params:
Name | Type | Attribute | Description |
other | number[] | 3d vector |
|
target | Array/Vector | optional array/vector to avoid mutating this vector |
public cross2(other: number[]): number source
Calculate the psudo cross product between this vector and the passed in argument. Only for 2d vectors!
Params:
Name | Type | Attribute | Description |
other | number[] | 2d vector |
public distance(other: number[]): number source
Calculate the distance between this coordinates to the coordinates supplied in the argument
Params:
Name | Type | Attribute | Description |
other | number[] | coordinates |
public dot(other: number[]): number source
Calculate the dot product between this vector and the passed in argument
Params:
Name | Type | Attribute | Description |
other | number[] | vector |
public isNull(epsilon: number): * source
Test if this vector is a null vector
Params:
Name | Type | Attribute | Description |
epsilon | number | epsilon |
Return:
* |
public negate(target: Array/Vector): Vector source
Negate all components of this vector
Params:
Name | Type | Attribute | Description |
target | Array/Vector | optional array/vector to avoid mutating this vector |
public normalize(target: Array/Vector): Vector source
Normalize this vector
Params:
Name | Type | Attribute | Description |
target | Array/Vector | optional array/vector to avoid mutating this vector |
public scale(factor: number, target: Array/Vector): Vector source
Scale this vector by a factor
Params:
Name | Type | Attribute | Description |
factor | number | scaling factor |
|
target | Array/Vector | optional array/vector to avoid mutating this vector |
public set(v: ...number): Vector source
Assign values to this vector
Params:
Name | Type | Attribute | Description |
v | ...number | values to set |
public sub(vectors: ...number[]): Vector source
Subtract one or more vectors from this vector
Params:
Name | Type | Attribute | Description |
vectors | ...number[] | vectors to subtract from this vector |
public subScaled(vector: number[], factor: number): Vector source
Subtract a scaled version of a vector from this vector
public swizzle(pattern: string, target: Array/Vector): Vector source
Mimic the swizzle feature in glsl. Supply the swizzle pattern as a string, using the defined accessors (xyzw, rgba, ijkl or stuv): ex: vec.swizzle('xxyw') or vec.swizzle('rrra)
Params:
Name | Type | Attribute | Description |
pattern | string | swizzle pattern |
|
target | Array/Vector | optional array/vector to avoid mutating this vector |