new Vector3(x, y, z)
Constructs a new 3D vector with the given values.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
x |
Number | 0 | The x component. |
y |
Number | 0 | The y component. |
z |
Number | 0 | The z component. |
Members
-
x :Number
-
The x component.
-
y :Number
-
The y component.
-
z :Number
-
The z component.
Methods
-
add(v) → {Vector3}
-
Adds the given 3D vector to this 3D vector.
Parameters:
Name Type Description v
Vector3 The vector to add.
-
addScalar(s) → {Vector3}
-
Adds the given scalar to this 3D vector.
Parameters:
Name Type Description s
Number The scalar to add.
-
addVectors(a, b) → {Vector3}
-
Adds two given 3D vectors and stores the result in this 3D vector.
Parameters:
Name Type Description a
Vector3 The first vector of the operation.
b
Vector3 The second vector of the operation.
-
angleTo(v) → {Number}
-
Computes the angle between this and the given vector.
Parameters:
Name Type Description v
Vector3 A 3D vector.
Returns:
Number -The angle in radians.
-
applyMatrix4(m) → {Vector3}
-
Multiplies the given 4x4 matrix with this 3D vector
Parameters:
Name Type Description m
Matrix4 A 4x4 matrix.
-
applyRotation(q) → {Vector3}
-
Multiplies the given quaternion with this 3D vector.
Parameters:
Name Type Description q
Quaternion A quaternion.
-
clamp(min, max) → {Vector3}
-
Ensures this 3D vector lies in the given min/max range.
-
clone() → {Vector3}
-
Creates a new 3D vector and copies all values from this 3D vector.
-
copy(v) → {Vector3}
-
Copies all values from the given 3D vector to this 3D vector.
Parameters:
Name Type Description v
Vector3 The vector to copy.
-
cross(v) → {Vector3}
-
Computes the cross product of this and the given 3D vector and stores the result in this 3D vector.
Parameters:
Name Type Description v
Vector3 A 3D vector.
-
crossVectors(a, b) → {Vector3}
-
Computes the cross product of the two given 3D vectors and stores the result in this 3D vector.
-
distanceTo(v) → {Number}
-
Computes the euclidean distance between this 3D vector and the given one.
Parameters:
Name Type Description v
Vector3 A 3D vector.
Returns:
Number -The euclidean distance between two 3D vectors.
-
divide(v) → {Vector3}
-
Divides the given 3D vector through this 3D vector.
Parameters:
Name Type Description v
Vector3 The vector to divide.
-
divideScalar(s) → {Vector3}
-
Divides the given scalar through this 3D vector.
Parameters:
Name Type Description s
Number The scalar to multiply.
-
divideVectors(a, b) → {Vector3}
-
Divides two given 3D vectors and stores the result in this 3D vector.
Parameters:
Name Type Description a
Vector3 The first vector of the operation.
b
Vector3 The second vector of the operation.
-
dot(v) → {Number}
-
Computes the dot product of this and the given 3D vector.
Parameters:
Name Type Description v
Vector3 The given 3D vector.
Returns:
Number -The results of the dor product.
-
equals(v) → {Boolean}
-
Returns true if the given 3D vector is deep equal with this 3D vector.
Parameters:
Name Type Description v
Vector3 The 3D vector to test.
Returns:
Boolean -The result of the equality test.
-
extractPositionFromMatrix(m) → {Vector3}
-
Extracts the position portion of the given 4x4 matrix and stores it in this 3D vector.
Parameters:
Name Type Description m
Matrix4 A 4x4 matrix.
-
fromArray(array, offset) → {Vector3}
-
Sets the components of this 3D vector from an array.
Parameters:
Name Type Default Description array
Array.<Number> An array.
offset
Number 0 An optional offset.
-
fromMatrix3Column(m, i) → {Vector3}
-
Sets the components of this 3D vector from a column of a 3x3 matrix.
Parameters:
Name Type Description m
Matrix3 A 3x3 matrix.
i
Number The index of the column.
-
fromMatrix4Column(m, i) → {Vector3}
-
Sets the components of this 3D vector from a column of a 4x4 matrix.
Parameters:
Name Type Description m
Matrix3 A 4x4 matrix.
i
Number The index of the column.
-
fromSpherical(radius, phi, theta) → {Vector3}
-
Sets the components of this 3D vector from a spherical coordinate.
Parameters:
Name Type Description radius
Number The radius.
phi
Number The polar or inclination angle in radians. Should be in the range of (−π/2, +π/2].
theta
Number The azimuthal angle in radians. Should be in the range of (−π, +π].
-
length() → {Number}
-
Computes the length of this 3D vector.
Returns:
Number -The length of this 3D vector.
-
manhattanDistanceTo(v) → {Number}
-
Computes the manhattan distance between this 3D vector and the given one.
Parameters:
Name Type Description v
Vector3 A 3D vector.
Returns:
Number -The manhattan distance between two 3D vectors.
-
manhattanLength() → {Number}
-
Computes the manhattan length of this 3D vector.
Returns:
Number -The manhattan length of this 3D vector.
-
max(v) → {Vector3}
-
Compares each vector component of this 3D vector and the given one and stores the maximum value in this instance.
Parameters:
Name Type Description v
Vector3 The 3D vector to check.
-
min(v) → {Vector3}
-
Compares each vector component of this 3D vector and the given one and stores the minimum value in this instance.
Parameters:
Name Type Description v
Vector3 The 3D vector to check.
-
multiply(v) → {Vector3}
-
Multiplies the given 3D vector with this 3D vector.
Parameters:
Name Type Description v
Vector3 The vector to multiply.
-
multiplyScalar(s) → {Vector3}
-
Multiplies the given scalar with this 3D vector.
Parameters:
Name Type Description s
Number The scalar to multiply.
-
multiplyVectors(a, b) → {Vector3}
-
Multiplies two given 3D vectors and stores the result in this 3D vector.
Parameters:
Name Type Description a
Vector3 The first vector of the operation.
b
Vector3 The second vector of the operation.
-
normalize() → {Vector3}
-
Normalizes this 3D vector.
-
reflect(normal) → {Vector3}
-
Reflects this vector along the given normal.
Parameters:
Name Type Description normal
Vector3 The normal vector.
-
set(x, y, z) → {Vector3}
-
Sets the given values to this 3D vector.
Parameters:
Name Type Description x
Number The x component.
y
Number The y component.
z
Number The z component.
-
squaredDistanceTo(v) → {Number}
-
Computes the squared euclidean distance between this 3D vector and the given one. Calling this method is faster than calling Vector3#distanceTo, since it avoids computing a square root.
Parameters:
Name Type Description v
Vector3 A 3D vector.
Returns:
Number -The squared euclidean distance between two 3D vectors.
-
squaredLength() → {Number}
-
Computes the squared length of this 3D vector. Calling this method is faster than calling Vector3#length, since it avoids computing a square root.
Returns:
Number -The squared length of this 3D vector.
-
sub(v) → {Vector3}
-
Subtracts the given 3D vector from this 3D vector.
Parameters:
Name Type Description v
Vector3 The vector to substract.
-
subScalar(s) → {Vector3}
-
Subtracts the given scalar from this 3D vector.
Parameters:
Name Type Description s
Number The scalar to substract.
-
subVectors(a, b) → {Vector3}
-
Subtracts two given 3D vectors and stores the result in this 3D vector.
Parameters:
Name Type Description a
Vector3 The first vector of the operation.
b
Vector3 The second vector of the operation.
-
toArray(array, offset) → {Array.<Number>}
-
Copies all values of this 3D vector to the given array.
Parameters:
Name Type Default Description array
Array.<Number> An array.
offset
Number 0 An optional offset.
Returns:
Array.<Number> -The array with the 3D vector components.
-
transformDirection(m) → {Vector3}
-
Transform this direction vector by the given 4x4 matrix.
Parameters:
Name Type Description m
Matrix4 A 4x4 matrix.