Constructor
new Vector3(x, y, z)
Creates a new vector.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
x |
Number | 0 | The x component. The default is 0. |
y |
Number | 0 | The y component. The default is 0. |
z |
Number | 0 | The z component. The default is 0. |
- Source:
Members
(static) one
A Vector3 with its x, y and z components equal to zero.
- Source:
(static) unitX
A unit Vector3 along the x axis.
- Source:
(static) unitY
A unit Vector3 along the y axis.
- Source:
(static) unitZ
A unit Vector3 along the z axis.
- Source:
(static) zero
A Vector3 with its x, y and z components equal to zero.
- Source:
Methods
add(vector) → {Vector3}
Adds the components of another vector.
Parameters:
Name | Type | Description |
---|---|---|
vector |
Vector3 | The vector to add. |
- Source:
Returns:
The vector.
- Type
- Vector3
addScalar(s) → {Vector3}
Adds a scalar to the x, y and z components of the vector.
Parameters:
Name | Type | Description |
---|---|---|
s |
Number | The scalar to add. |
- Source:
Returns:
The vector.
- Type
- Vector3
addValues(x, y, z) → {Vector3}
Adds a value to each component of the vector.
Parameters:
Name | Type | Description |
---|---|---|
x |
Number | The value to add to the x component. |
y |
Number | The value to add to the y component. |
z |
Number | The value to add to the z component. |
- Source:
Returns:
The vector.
- Type
- Vector3
addVectors(u, v) → {Vector3}
Sets the vector to the addition of two vectors.
Parameters:
Name | Type | Description |
---|---|---|
u |
Vector3 | The first vector. |
v |
Vector3 | The second vector. |
- Source:
Returns:
The vector.
- Type
- Vector3
clone() → {Vector3}
Creates a clone of the vector.
- Source:
Returns:
The cloned vector.
- Type
- Vector3
copy(vector) → {Vector3}
Copies the components of another vector.
Parameters:
Name | Type | Description |
---|---|---|
vector |
Vector3 | The vector to copy. |
- Source:
Returns:
The vector.
- Type
- Vector3
crossVectors(u, v) → {Vector3}
Sets the vector to the cross product between two vectors.
Parameters:
Name | Type | Description |
---|---|---|
u |
Vector3 | The first vector. |
v |
Vector3 | The second vector. |
- Source:
Returns:
The vector.
- Type
- Vector3
distanceTo(vector) → {Number}
Calculates the distance to another vector.
Parameters:
Name | Type | Description |
---|---|---|
vector |
Vector3 | The vector to calculate the distance to. |
- Source:
Returns:
The distance.
- Type
- Number
distanceToSquared(vector) → {Number}
Calculates the squared distance to another vector.
Parameters:
Name | Type | Description |
---|---|---|
vector |
Vector3 | The vector to calculate the squared distance to. |
- Source:
Returns:
The squared distance.
- Type
- Number
divideScalar(s) → {Vector3}
Divides the components of the vector by a scalar.
Parameters:
Name | Type | Description |
---|---|---|
s |
Number | The scalar to divide. |
- Source:
Returns:
The vector.
- Type
- Vector3
dot(vector) → {Number}
Calculates the dot product with another vector.
Parameters:
Name | Type | Description |
---|---|---|
vector |
Vector3 | The vector to calculate the dot product with. |
- Source:
Returns:
The dot product.
- Type
- Number
equals(vector) → {Boolean}
Compares if the components of the vector are equal to the components of another vector.
Parameters:
Name | Type | Description |
---|---|---|
vector |
Vector3 | The vector to compare the components to. |
- Source:
Returns:
A value indicating whether all the components are equal.
- Type
- Boolean
length() → {Number}
Calculates the length of the vector.
- Source:
Returns:
The length.
- Type
- Number
lengthSquared() → {Number}
Calculates the squared length of the vector.
- Source:
Returns:
The squared length.
- Type
- Number
lerpVectors(u, v, t) → {Vector3}
Sets the vector to the interpolation of two other vectors.
Parameters:
Name | Type | Description |
---|---|---|
u |
Vector3 | The first vector of the interpolation. |
v |
Vector3 | The second vector of the interpolation. |
t |
Number | The interpolation value. |
- Source:
Returns:
The vector.
- Type
- Vector3
multiplyScalar(s) → {Vector3}
Multiplies the components of the vector by a scalar.
Parameters:
Name | Type | Description |
---|---|---|
s |
Number | The scalar to multiply. |
- Source:
Returns:
The vector.
- Type
- Vector3
negate() → {Vector3}
Negates the components of the vector.
- Source:
Returns:
The vector.
- Type
- Vector3
negateVector(vector) → {Vector3}
Sets the components to the negation of another vector.
Parameters:
Name | Type | Description |
---|---|---|
vector |
Vector3 | The vector to negate. |
- Source:
Returns:
The vector.
- Type
- Vector3
normalize() → {Vector3}
Normalizes the vector.
When the vector length is 0, it does nothing.
- Source:
Returns:
The vector.
- Type
- Vector3
set(x, y, z) → {Vector3}
Sets the x, y and z components of the vector.
Parameters:
Name | Type | Description |
---|---|---|
x |
Number | The x component. |
y |
Number | The y component. |
z |
Number | The z component. |
- Source:
Returns:
The vector.
- Type
- Vector3
setX(value) → {Vector3}
Sets the x component of the vector.
Parameters:
Name | Type | Description |
---|---|---|
value |
Number | The x component. |
- Source:
Returns:
The vector.
- Type
- Vector3
setY(value) → {Vector3}
Sets the y component of the vector.
Parameters:
Name | Type | Description |
---|---|---|
value |
Number | The y component. |
- Source:
Returns:
The vector.
- Type
- Vector3
setZ(value) → {Vector3}
Sets the z component of the vector.
Parameters:
Name | Type | Description |
---|---|---|
value |
Number | The z component. |
- Source:
Returns:
The vector.
- Type
- Vector3
subtract(vector) → {Vector3}
Subtracts the components of another vector.
Parameters:
Name | Type | Description |
---|---|---|
vector |
Vector3 | The vector to subtract. |
- Source:
Returns:
The vector.
- Type
- Vector3
subtractScalar(s) → {Vector3}
Subtracts a scalar from the x, y and z components of the vector.
Parameters:
Name | Type | Description |
---|---|---|
s |
Number | The scalar to subtract. |
- Source:
Returns:
The vector.
- Type
- Vector3
subtractValues(x, y, z) → {Vector3}
Subtracts a value from each component of the vector.
Parameters:
Name | Type | Description |
---|---|---|
x |
Number | The value to subtract from the x component. |
y |
Number | The value to subtract from the y component. |
z |
Number | The value to subtract from the z component. |
- Source:
Returns:
The vector.
- Type
- Vector3
subtractVectors(u, v) → {Vector3}
Sets the vector to the difference of two vectors.
Parameters:
Name | Type | Description |
---|---|---|
u |
Vector3 | The first vector. |
v |
Vector3 | The second vector. |
- Source:
Returns:
The vector.
- Type
- Vector3
transform(matrix3) → {Vector3}
Transforms the vector by applying a Matrix3 to it.
Parameters:
Name | Type | Description |
---|---|---|
matrix3 |
Matrix3 | The transform matrix. |
- Source:
Returns:
The vector.
- Type
- Vector3
transformDirection(matrix4) → {Vector3}
Transforms the vector with a Matrix4.
It considers the homogeneous coordinate as 0.
Parameters:
Name | Type | Description |
---|---|---|
matrix4 |
Matrix4 | The transform matrix. |
- Source:
Returns:
The vector.
- Type
- Vector3
transformDirectionVector(vector, matrix4) → {Vector3}
Sets the vector to the components of another vector transformed by a matrix.
It considers the homogeneous coordinate as 0.
Parameters:
Name | Type | Description |
---|---|---|
vector |
Vector3 | The vector to transform. |
matrix4 |
Matrix4 | The transform matrix. |
- Source:
Returns:
The vector.
- Type
- Vector3
transformPosition(matrix4) → {Vector3}
Transforms the vector with a Matrix4.
It considers the homogeneous coordinate as 1.
Parameters:
Name | Type | Description |
---|---|---|
matrix4 |
Matrix4 | The transform matrix. |
- Source:
Returns:
The vector.
- Type
- Vector3
transformPositionVector(vector, matrix4) → {Vector3}
Sets the vector to the components of another vector transformed by a matrix.
It considers the homogeneous coordinate as 1.
Parameters:
Name | Type | Description |
---|---|---|
vector |
Vector3 | The vector to transform. |
matrix4 |
Matrix4 | The transform matrix. |
- Source:
Returns:
The vector.
- Type
- Vector3
transformVector(vector, matrix3) → {Vector3}
Sets the vector to the components of another vector transformed by a matrix.
Parameters:
Name | Type | Description |
---|---|---|
vector |
Vector3 | The vector to transform. |
matrix3 |
Matrix3 | The transform matrix. |
- Source:
Returns:
The vector.
- Type
- Vector3