Return the negative of the vector : Vector
| Parameter | Type | Description |
|---|---|---|
| vector | Vector | Vector to negative |
const myVector = new Float32Array([2, 5, -7]);
const negativeVector = GLMath.Vector.negative( myVector );
//myVector : [2, 5, -7]
//negativeVector : [-2, -5, 7]
Return the reverse of the vector : Vector
| Parameter | Type | Description |
|---|---|---|
| vector | Vector | Vector to reverse |
const myVector = new Float32Array([2, 5, -7]);
const reverseVector = GLMath.Vector.reverse( myVector );
//myVector : [2, 5, -7]
//negativeVector : [-7, 5, 2]
Return the length(magnitude) of the vector: Number
| Parameter | Type | Description |
|---|---|---|
| vector | Vector | Vector to calculate length of |
const myVector = new Float32Array([3, 4]);
const length = GLMath.Vector.length( myVector ); // 5
Return normalized vector: Vector
| Parameter | Type | Description |
|---|---|---|
| vector | Vector | Vector to normalize |
const myVector = new Float32Array([3, 4]);
const normalizedVector = GLMath.Vector.normalize( myVector ); // [0.6, 0.8]
Return scaled vector: Vector
| Parameter | Type | Description |
|---|---|---|
| vector | Vector | Vector to scale |
| number | Number | Factor |
const myVector = new Float32Array([3, 4]);
const resultVector = GLMath.Vector.scale( myVector, 3 ); // [9, 12]
Return the sum of the vectors: Vector
| Parameter | Type | Description |
|---|---|---|
| vectorA | Vector | First Vector to add |
| vectorB | Vector | Second Vector to add |
const resultVector = GLMath.Vector.add(
new Float32Array([3, 5 , 1]),
new Float32Array([2, 1, -2])
); // [5, 6, -1]
Return the difference vector: Vector
| Parameter | Type | Description |
|---|---|---|
| vectorA | Vector | Minuend Vector |
| vectorB | Vector | Subtrahend Vector |
const resultVector = GLMath.Vector.subtract(
new Float32Array([5, 6]),
new Float32Array([2, 1])
); // [3, 5]
Return the component-wise multiplication of the two vectors: Vector
| Parameter | Type | Description |
|---|---|---|
| vectorA | Vector | First Vector to multiply |
| vectorB | Vector | Second Vector to multiply |
const resultVector = GLMath.Vector.multiply(
new Float32Array([2, 3]),
new Float32Array([4, 5])
); // [8, 15]
Return the dot product of the two vectors: Number
| Parameter | Type | Description |
|---|---|---|
| vectorA | Vector | Left operand |
| vectorB | Vector | Right operand |
const resultVector = GLMath.Vector.dot(
new Float32Array([-6, 8]),
new Float32Array([5, 12])
); // 66
Return the cross product of the two vectors: Vector (3D)
| Parameter | Type | Description |
|---|---|---|
| vectorA | Vector (3D) | Left operand |
| vectorB | Vector (3D) | Right operand |
const resultVector = GLMath.Vector.cross(
new Float32Array([2, 3, 4]),
new Float32Array([5, 6, 7])
); // [-3, 6, -3]
Return the 2D Vector of the given angle: Vector (2D)
| Parameter | Type | Description |
|---|---|---|
| angle | Radian | The Angle in radian |
const vector = GLMath.Vector.fromAngle(Math.PI / 2); // [0, 1]
Return the Angle of the Vector: Radian
| Parameter | Type | Description |
|---|---|---|
| vector | Vector(2D) | Two dimensional vector |
const myVector = new Float32Array([1, 1]);
const vector = GLMath.Vector.toAngle(myVector); // Math.PI/4
Return the rotated vector: Vector (2D)
| Parameter | Type | Description |
|---|---|---|
| vector | Vector(2D) | 2D Vector to rotate |
| angle | Radian | Angle(Radian) of rotation |
const myVector = new Float32Array([0, 1]);
const vector = GLMath.Vector.rotate(myVector, Math.PI / 2); // [-1, 0]
Return the swizzled vector: Vector (2D)
| Parameter | Type | Description |
|---|---|---|
| vector | Vector | Vector to swizzle |
| swizz | Array of Integers | Array that contains index of wanted components (Negative Index means to negative value) |
const X = 0,
Y = 1,
Z = 2;
const myVector = new Float32Array([5, -4, 7]);
const swizz = [Y, -Y, Z, -X, X];
const resultVector = GLMath.Vector.swizzle(myVector, swizz); // [-4, 4, 7, -5, 5]