Creates a new Vector3.
Optional
x: number = 0The x value of this vector.
Optional
y: number = 0The y value of this vector.
Optional
z: number = 0The z value of this vector.
0
0
0
Read-only flag to check if a given object is of type Vector.
Read-only flag to check if a given object is of type Vector3.
Adds the scalar value s to this vector's x, y and z values.
This instance.
The scalar
Sets this vector to a + b.
This instance.
Returns the angle between this vector and vector v in radians.
The angle.
Applies a Quaternion transform to this vector.
This instance.
The x, y and z components of this vector are rounded up to the nearest integer value.
This instance.
Restrict this vector component values to the range of their respective min and max vector component values.
If this vector's x, y or z value is greater than the max vector's x, y or z value, it is replaced by the corresponding value.
If this vector's x, y or z value is less than the min vector's x, y or z value, it is replaced by the corresponding value.
This instance.
Restrict this vector length the range [min,max].
If this vector's length is greater than the max value, the vector will be scaled down so its length is the max value.
If this vector's length is less than the min value, the vector will be scaled up so its length is the min value.
This instance.
The minimum value the length will be clamped to
The maximum value the length will be clamped to
Restrict this vector component values to the range [minVal,maxVal].
If this vector's x, y or z values are greater than the max value, they are replaced by the max value.
If this vector's x, y or z values are less than the min value, they are replaced by the min value.
This instance.
The minimum component value
The maximum component value
Create a new vector using the component values of this vector.
A new vector3 with the same x, y and z values as this one.
Sets this vector to cross product of a and b.
This instance.
Computes the distance from this vector to v.
The distance.
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.
The squared distance.
Divides this vector by scalar s. Sets vector to ( 0, 0, 0 ) if s = 0.
This instance.
Calculate the dot product of this vector and v.
The dot product.
Checks for strict equality of this vector and v.
true if equal; false otherwise.
The components of this vector are rounded down to the nearest integer value.
This instance.
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 ].
This instance.
The source array.
Optional
offset: number = 0Offset into the array.
Get a component value by index, [x,y,z]. If index equals 0 returns the x value. If index equals 1 returns the y value. If index equals 2 returns the z value.
The x, y or z component specified by index.
Index of component to access.
Computes the Euclidean length (straight-line length) from (0, 0, 0) to (x, y, z).
The square-root of the sum of the components squared.
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.
The sum of the components squared.
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.
This instance.
The vector to interpolate towards.
The interpolation factor, typically in the closed interval [0, 1].
Sets this vector to be the vector linearly interpolated between v1 and v2 where alpha is the percent distance along the line connecting the two vectors - alpha = 0 will be v1, and alpha = 1 will be v2.
This instance.
Computes the Manhattan distance from this vector to v.
The Manhattan distance.
Computes the Manhattan length of this vector.
The Manhattan length.
Multiplies this vector by scalar s.
This instance.
Sets this vector equal to a * b, component-wise.
This instance.
Inverts this vector - i.e. sets x = -x, y = -y and z = -z.
This instance.
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.
This instance.
Sets each component of this vector to a pseudo-random value between 0 and 1, excluding 1.
This instance.
Sets each component of this vector to a pseudo-random value between 0 and 1, excluding 1.
This instance.
The components of this vector are rounded to the nearest integer value.
This instance.
The components of this vector are rounded towards zero (up if negative, down if positive) to an integer value.
This instance.
Sets the x, y and z components of this vector.
This instance.
The x value of this vector.
The y value of this vector.
Optional
z: numberThe z value of this vector.
Update a component by index. If index equals 0 set x to value. If index equals 1 set y to value. If index equals 2 set z to value
This instance.
The component to update
New value
Sets this vector from the cylindrical coordinates c.
This instance.
Sets this vector from the cylindrical coordinates radius, theta and y.
This instance.
Sets this vector from the spherical coordinates radius, phi and theta.
This instance.
Set this vector to a vector with the same direction as this one, but the specified length.
This instance.
Set the x, y and z values of this vector equal to scalar.
This instance.
The scalar value
Replace this vector's x value with x.
This instance.
The new x value.
Replace this vector's y value with y.
This instance.
The new x value.
Replace this vector's z value with z.
This instance.
The new z value.
Subtracts s from this vector's x, y and z compnents.
This instance.
The subtracting vector
Sets this vector to a - b.
This instance.
Returns an array [x, y, z], or copies x, y and z into the provided array.
Array with this vector compoonent values, [x,y,z].
Array to store this vector to. If this is not provided a new array will be created.
Optional offset into the array.
Represents a 3D vector. A 3D vector is an ordered triplet of numbers (labeled x, y, and z), which can be used to represent a number of things, such as:
There are other things a 3D vector can be used to represent, such as momentum vectors and so on.
Iterating through a Vector3 instance will yield its components (x, y, z) in the corresponding order.
Example