Constructor
new Vector3(xopt, yopt, zopt)
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
x | Number | <optional> | 0 | the x value of this vector. Default is 0. |
y | Number | <optional> | 0 | the y value of this vector. Default is 0. |
z | Number | <optional> | 0 | the z value of this vector. Default is 0. |
Methods
add(v) → {t3d.Vector3}
Adds v to this vector.
Parameters:
Name | Type | Description |
---|---|---|
v | t3d. |
Returns:
- Type:
- t3d.
Vector3
addScalar(s) → {t3d.Vector3}
Adds the scalar value s to this vector's x, y and z values.
Parameters:
Name | Type | Description |
---|---|---|
s | Number |
Returns:
- Type:
- t3d.
Vector3
addScaledVector(v, s) → {t3d.Vector3}
Adds the multiple of v and s to this vector.
Parameters:
Name | Type | Description |
---|---|---|
v | t3d. | |
s | Number |
Returns:
- Type:
- t3d.
Vector3
addVectors(a, b) → {t3d.Vector3}
Sets this vector to a + b.
Parameters:
Name | Type | Description |
---|---|---|
a | t3d. | |
b | t3d. |
Returns:
- Type:
- t3d.
Vector3
applyMatrix3(m) → {t3d.Vector3}
Multiplies this vector by m
Parameters:
Name | Type | Description |
---|---|---|
m | t3d. |
Returns:
- Type:
- t3d.
Vector3
applyMatrix4(m) → {t3d.Vector3}
Multiplies this vector (with an implicit 1 in the 4th dimension) and m, and divides by perspective.
Parameters:
Name | Type | Description |
---|---|---|
m | t3d. |
Returns:
- Type:
- t3d.
Vector3
applyQuaternion(q) → {t3d.Vector3}
Applies a Quaternion transform to this vector.
Parameters:
Name | Type | Description |
---|---|---|
q | t3d. |
Returns:
- Type:
- t3d.
Vector3
clone() → {t3d.Vector3}
Returns a new vector3 with the same x, y and z values as this one.
Returns:
- Type:
- t3d.
Vector3
copy(v) → {t3d.Vector3}
Copies the values of the passed vector3's x, y and z properties to this vector3.
Parameters:
Name | Type | Description |
---|---|---|
v | t3d. |
Returns:
- Type:
- t3d.
Vector3
cross(v) → {t3d.Vector3}
Sets this vector to cross product of itself and v.
Parameters:
Name | Type | Description |
---|---|---|
v | t3d. |
Returns:
- Type:
- t3d.
Vector3
crossVectors(a, b) → {t3d.Vector3}
Sets this vector to cross product of a and b.
Parameters:
Name | Type | Description |
---|---|---|
a | t3d. | |
b | t3d. |
Returns:
- Type:
- t3d.
Vector3
distanceTo(v) → {Number}
Computes the distance from this vector to v.
Parameters:
Name | Type | Description |
---|---|---|
v | t3d. |
Returns:
- Type:
- Number
distanceToSquared(v) → {Number}
Computes the squared distance from this vector to v. If you are just comparing the distance with another distance, you should compare the distance squared instead as it is slightly more efficient to calculate.
Parameters:
Name | Type | Description |
---|---|---|
v | t3d. |
Returns:
- Type:
- Number
dot(a) → {Number}
Calculate the dot product of this vector and v.
Parameters:
Name | Type | Description |
---|---|---|
a | t3d. |
Returns:
- Type:
- Number
equals(v) → {Boolean}
Checks for strict equality of this vector and v.
Parameters:
Name | Type | Description |
---|---|---|
v | t3d. |
Returns:
- Type:
- Boolean
fromArray(array, offsetopt, denormalizeopt) → {t3d.Vector3}
Sets this vector's x value to be array[ offset + 0 ], y value to be array[ offset + 1 ] and z value to be array[ offset + 2 ].
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
array | Array.<Number> | the source array. | ||
offset | Number | <optional> | 0 | offset into the array. |
denormalize | Boolean | <optional> | false | if true, denormalize the values, and array should be a typed array. |
Returns:
- Type:
- t3d.
Vector3
getLength() → {Number}
Computes the Euclidean length (straight-line length) from (0, 0, 0) to (x, y, z).
Returns:
- Type:
- Number
getLengthSquared() → {Number}
Computes the square of the Euclidean length (straight-line length) from (0, 0, 0) to (x, y, z). If you are comparing the lengths of vectors, you should compare the length squared instead as it is slightly more efficient to calculate.
Returns:
- Type:
- Number
lerp(v, alpha) → {t3d.Vector3}
Linearly interpolate between this vector and v, where alpha is the percent distance along the line - alpha = 0 will be this vector, and alpha = 1 will be v.
Parameters:
Name | Type | Description |
---|---|---|
v | t3d. | |
alpha | Number |
Returns:
- Type:
- t3d.
Vector3
lerpVectors(v1, v2, ratio) → {t3d.Vector3}
Sets this vector to be the vector linearly interpolated between v1 and v2 where ratio is the percent distance along the line connecting the two vectors - ratio = 0 will be v1, and ratio = 1 will be v2.
Parameters:
Name | Type | Description |
---|---|---|
v1 | t3d. | |
v2 | t3d. | |
ratio | Number |
Returns:
- Type:
- t3d.
Vector3
max(v) → {t3d.Vector3}
If this vector's x, y or z value is less than v's x, y or z value, replace that value with the corresponding max value.
Parameters:
Name | Type | Description |
---|---|---|
v | t3d. |
Returns:
- Type:
- t3d.
Vector3
min(v) → {t3d.Vector3}
If this vector's x, y or z value is greater than v's x, y or z value, replace that value with the corresponding min value.
Parameters:
Name | Type | Description |
---|---|---|
v | t3d. |
Returns:
- Type:
- t3d.
Vector3
multiply(v) → {t3d.Vector3}
Multiplies this vector by v.
Parameters:
Name | Type | Description |
---|---|---|
v | t3d. |
Returns:
- Type:
- t3d.
Vector3
multiplyScalar(scalar) → {t3d.Vector3}
Multiplies this vector by scalar s.
Parameters:
Name | Type | Description |
---|---|---|
scalar | Number |
Returns:
- Type:
- t3d.
Vector3
negate() → {t3d.Vector3}
Inverts this vector - i.e. sets x = -x, y = -y and z = -z.
Returns:
- Type:
- t3d.
Vector3
normalize(thicknessopt)
Convert this vector to a unit vector - that is, sets it equal to a vector with the same direction as this one, but length 1.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
thickness | Number | <optional> | 1 |
project(camera) → {t3d.Vector3}
Projects this vector from world space into the camera's normalized device coordinate (NDC) space.
Parameters:
Name | Type | Description |
---|---|---|
camera | t3d. |
Returns:
- Type:
- t3d.
Vector3
reflect(narmal) → {t3d.Vector3}
Reflect this vector off of plane orthogonal to normal. Normal is assumed to have unit length.
Parameters:
Name | Type | Description |
---|---|---|
narmal | t3d. | the normal to the reflecting plane |
Returns:
- Type:
- t3d.
Vector3
set(x, y, z) → {t3d.Vector3}
Sets the x, y and z components of this vector.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
x | Number | 0 | |
y | Number | 0 | |
z | Number | 0 |
Returns:
- Type:
- t3d.
Vector3
setFromMatrixColumn(m, index) → {t3d.Vector3}
Sets this vector's x, y and z components from index column of matrix.
Parameters:
Name | Type | Description |
---|---|---|
m | t3d. | |
index | Number |
Returns:
- Type:
- t3d.
Vector3
setFromMatrixPosition(m) → {t3d.Vector3}
Sets this vector to the position elements of the transformation matrix m.
Parameters:
Name | Type | Description |
---|---|---|
m | t3d. |
Returns:
- Type:
- t3d.
Vector3
setFromMatrixScale(m) → {t3d.Vector3}
Sets this vector to the scale elements of the transformation matrix m.
Parameters:
Name | Type | Description |
---|---|---|
m | t3d. |
Returns:
- Type:
- t3d.
Vector3
setFromSpherical(s) → {t3d.Vector3}
Sets this vector from the spherical coordinates s.
Parameters:
Name | Type | Description |
---|---|---|
s | t3d. |
Returns:
- Type:
- t3d.
Vector3
setScalar(scalar) → {t3d.Vector3}
Set the x, y and z values of this vector both equal to scalar.
Parameters:
Name | Type | Description |
---|---|---|
scalar | Number |
Returns:
- Type:
- t3d.
Vector3
sub(v) → {t3d.Vector3}
Subtracts v from this vector.
Parameters:
Name | Type | Description |
---|---|---|
v | t3d. |
Returns:
- Type:
- t3d.
Vector3
subVectors(a, b) → {t3d.Vector3}
Sets this vector to a - b.
Parameters:
Name | Type | Description |
---|---|---|
a | t3d. | |
b | t3d. |
Returns:
- Type:
- t3d.
Vector3
subtract(a, targetopt) → {t3d.Vector3}
Subtracts a from this vector.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
a | t3d. | ||
target | t3d. | <optional> |
Returns:
- Type:
- t3d.
Vector3
toArray(arrayopt, offsetopt, normalizeopt) → {Array.<Number>}
Returns an array [x, y, z], or copies x, y and z into the provided array.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
array | Array.<Number> | <optional> | array to store this vector to. If this is not provided a new array will be created. | |
offset | Number | <optional> | 0 | offset into the array. |
normalize | Boolean | <optional> | false | if true, normalize the values, and array should be a typed array. |
Returns:
- Type:
- Array.<Number>
transformDirection(m) → {t3d.Vector3}
Transforms the direction of this vector by a matrix (the upper left 3 x 3 subset of a m) and then
Parameters:
Name | Type | Description |
---|---|---|
m | t3d. |
Returns:
- Type:
- t3d.
Vector3
unproject(camera) → {t3d.Vector3}
Projects this vector from the camera's normalized device coordinate (NDC) space into world space.
Parameters:
Name | Type | Description |
---|---|---|
camera | t3d. |
Returns:
- Type:
- t3d.
Vector3