Class: Vec3

Vec3(x, y, z)

Represents a three-component vector. Access the X component of the vector as v[0], the Y component as v[1] and the Z component as v[2].

Constructor

new Vec3(x, y, z)

Constructs a three-component vector.
Parameters:
Name Type Description
x Number X component of vector.
y Number Y component of vector.
z Number Z component of vector.
Source:

Extends

  • Float64Array

Members

(static) ZERO :Vec3

A vector corresponding to the origin.
Type:
Source:

Methods

add(addend) → {Vec3}

Adds a specified vector to this vector.
Parameters:
Name Type Description
addend Vec3 The vector to add.
Source:
Throws:
If the addend is null or undefined.
Type
ArgumentError
Returns:
This vector after adding the specified vector to it.
Type
Vec3

copy(vector) → {Vec3}

Copies the components of a specified vector to this vector.
Parameters:
Name Type Description
vector Vec3 The vector to copy.
Source:
Throws:
If the specified vector is null or undefined.
Type
ArgumentError
Returns:
This vector set to the X, Y and Z values of the specified vector.
Type
Vec3

cross(vector) → {Vec3}

Computes the cross product of this vector and a specified vector, modifying this vector.
Parameters:
Name Type Description
vector Vec3 The vector to cross with this vector.
Source:
Throws:
If the specified vector is null or undefined.
Type
ArgumentError
Returns:
This vector set to the cross product of itself and the specified vector.
Type
Vec3

distanceTo(vector) → {number}

Computes the distance from this vector to another vector.
Parameters:
Name Type Description
vector Vec3 The vector to compute the distance to.
Source:
Throws:
If the specified vector is null or undefined.
Type
ArgumentError
Returns:
The distance between the vectors.
Type
number

distanceToSquared(vector) → {Number}

Computes the squared distance from this vector to a specified vector.
Parameters:
Name Type Description
vector Vec3 The vector to compute the distance to.
Source:
Throws:
If the specified vector is null or undefined.
Type
ArgumentError
Returns:
The squared distance between the vectors.
Type
Number

divide(divisor) → {Vec3}

Divides this vector by a scalar.
Parameters:
Name Type Description
divisor Number The scalar to divide this vector by.
Source:
Returns:
This vector divided by the specified scalar.
Type
Vec3

dot(vector) → {Number}

Computes the scalar dot product of this vector and a specified vector.
Parameters:
Name Type Description
vector Vec3 The vector to multiply.
Source:
Throws:
If the specified vector is null or undefined.
Type
ArgumentError
Returns:
The dot product of the two vectors.
Type
Number

equals(vector) → {Boolean}

Indicates whether the components of this vector are identical to those of a specified vector.
Parameters:
Name Type Description
vector Vec3 The vector to test.
Source:
Returns:
true if the components of this vector are equal to those of the specified one, otherwise false.
Type
Boolean

magnitude() → {Number}

Computes the magnitude of this vector.
Source:
Returns:
The magnitude of this vector.
Type
Number

magnitudeSquared() → {Number}

Computes the squared magnitude of this vector.
Source:
Returns:
The squared magnitude of this vector.
Type
Number

mix(vector, weight) → {Vec3}

Mixes (interpolates) a specified vector with this vector, modifying this vector.
Parameters:
Name Type Description
vector Vec3 The vector to mix with this one.
weight Number The relative weight of this vector.
Source:
Throws:
If the specified vector is null or undefined.
Type
ArgumentError
Returns:
This vector modified to the mix of itself and the specified vector.
Type
Vec3

multiply(scalar) → {Vec3}

Multiplies this vector by a scalar.
Parameters:
Name Type Description
scalar Number The scalar to multiply this vector by.
Source:
Returns:
This vector multiplied by the specified scalar.
Type
Vec3

multiplyByMatrix(matrix) → {Vec3}

Multiplies this vector by a 4x4 matrix. The multiplication is performed with an implicit W component of 1. The resultant W component of the product is then divided through the X, Y, and Z components.
Parameters:
Name Type Description
matrix Matrix The matrix to multiply this vector by.
Source:
Throws:
ArgumentError If the specified matrix is null or undefined.
Returns:
This vector multiplied by the specified matrix.
Type
Vec3

negate() → {Vec3}

Negates the components of this vector.
Source:
Returns:
This vector, negated.
Type
Vec3

normalize() → {Vec3}

Normalizes this vector to a unit vector.
Source:
Returns:
This vector, normalized.
Type
Vec3

set(x, y, z) → {Vec3}

Assigns the components of this vector.
Parameters:
Name Type Description
x Number The X component of the vector.
y Number The Y component of the vector.
z Number The Z component of the vector.
Source:
Returns:
This vector with the specified components assigned.
Type
Vec3

subtract(subtrahend) → {Vec3}

Subtracts a specified vector from this vector.
Parameters:
Name Type Description
subtrahend Vec3 The vector to subtract
Source:
Throws:
If the subtrahend is null or undefined.
Type
ArgumentError
Returns:
This vector after subtracting the specified vector from it.
Type
Vec3

swap(that) → {Vec3}

Swaps this vector with that vector. This vector's components are set to the values of the specified vector's components, and the specified vector's components are set to the values of this vector's components.
Parameters:
Name Type Description
that Vec3 The vector to swap.
Source:
Returns:
This vector set to the values of the specified vector.
Type
Vec3

toString() → {String}

Returns a string representation of this vector.
Source:
Returns:
A string representation of this vector, in the form "(x, y, z)".
Type
String

(static) areColinear(a, b, c) → {Boolean}

Indicates whether three vectors are colinear.
Parameters:
Name Type Description
a Vec3 The first vector.
b Vec3 The second vector.
c Vec3 The third vector.
Source:
Throws:
If any of the specified vectors are null or undefined.
Type
ArgumentError
Returns:
true if the vectors are colinear, otherwise false.
Type
Boolean

(static) average(vectors, result) → {Vec3}

Computes the average of a specified array of vectors.
Parameters:
Name Type Description
vectors Array.<Vec3> The vectors whose average to compute.
result Vec3 A pre-allocated Vec3 in which to return the computed average.
Source:
Throws:
If the specified array of vectors is null, undefined or empty or the specified result argument is null or undefined.
Type
ArgumentError
Returns:
The result argument set to the average of the specified array of vectors.
Type
Vec3

(static) averageOfBuffer(points, result) → {Vec3}

Computes the average of a specified array of points packed into a single array.
Parameters:
Name Type Description
points Float32Array | Float64Array | Array.<Number> The points whose average to compute.
result Vec3 A pre-allocated Vec3 in which to return the computed average.
Source:
Throws:
If the specified array of points is null, undefined or empty or the result argument is null or undefined.
Type
ArgumentError
Returns:
The result argument set to the average of the specified array of points.
Type
Vec3

(static) computeBufferNormal(coords, stride) → {Vec3}

Computes a unit-normal vector for a buffer of coordinate triples. The normal vector is computed from the first three non-colinear points in the buffer.
Parameters:
Name Type Description
coords Array.<Number> The coordinates, in the order x0, y0, z0, x1, y1, z1, ...
stride Number The number of numbers between successive points. 0 indicates that the points are arranged one immediately after the other, as would the value 3.
Source:
Returns:
The computed unit-length normal vector.
Type
Vec3

(static) computeTriangleNormal(a, b, c) → {Vec3}

Computes the normal vector of a specified triangle.
Parameters:
Name Type Description
a Vec3 The triangle's first vertex.
b Vec3 The triangle's second vertex.
c Vec3 The triangle's third vertex.
Source:
Throws:
If any of the specified vectors are null or undefined.
Type
ArgumentError
Returns:
The triangle's unit-normal vector.
Type
Vec3

(static) findThreeIndependentVertices(coords, stride) → {Array.<Vec3>}

Finds three non-colinear points in an array of coordinates.
Parameters:
Name Type Description
coords Array.<Number> The coordinates, in the order x0, y0, z0, x1, y1, z1, ...
stride Number The number of numbers between successive points. 0 indicates that the points are arranged one immediately after the other, as would the value 3.
Source:
Returns:
Three non-colinear points from the input array of coordinates, or null if three non-colinear points could not be found or the specified coordinates array is null, undefined or contains fewer than three points.
Type
Array.<Vec3>