[name]

Class representing a 3D [link:https://en.wikipedia.org/wiki/Vector_space 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, however these are the most common uses in three.js.

Iterating through a [name] instance will yield its components `(x, y, z)` in the corresponding order.

Code Example

const a = new THREE.Vector3( 0, 1, 0 ); //no arguments; will be initialised to (0, 0, 0) const b = new THREE.Vector3( ); const d = a.distanceTo( b );

Constructor

[name]( [param:Float x], [param:Float y], [param:Float z] )

[page:Float x] - the x value of this vector. Default is `0`.
[page:Float y] - the y value of this vector. Default is `0`.
[page:Float z] - the z value of this vector. Default is `0`.

Creates a new [name].

Properties

[property:Boolean isVector3]

Read-only flag to check if a given object is of type [name].

[property:Float x]

[property:Float y]

[property:Float z]

Methods

[method:this add]( [param:Vector3 v] )

Adds [page:Vector3 v] to this vector.

[method:this addScalar]( [param:Float s] )

Adds the scalar value s to this vector's [page:.x x], [page:.y y] and [page:.z z] values.

[method:this addScaledVector]( [param:Vector3 v], [param:Float s] )

Adds the multiple of [page:Vector3 v] and [page:Float s] to this vector.

[method:this addVectors]( [param:Vector3 a], [param:Vector3 b] )

Sets this vector to [page:Vector3 a] + [page:Vector3 b].

[method:this applyAxisAngle]( [param:Vector3 axis], [param:Float angle] )

[page:Vector3 axis] - A normalized [page:Vector3].
[page:Float angle] - An angle in radians.

Applies a rotation specified by an axis and an angle to this vector.

[method:this applyEuler]( [param:Euler euler] )

Applies euler transform to this vector by converting the [page:Euler] object to a [page:Quaternion] and applying.

[method:this applyMatrix3]( [param:Matrix3 m] )

Multiplies this vector by [page:Matrix3 m]

[method:this applyMatrix4]( [param:Matrix4 m] )

Multiplies this vector (with an implicit 1 in the 4th dimension) by m, and divides by perspective.

[method:this applyNormalMatrix]( [param:Matrix3 m] )

Multiplies this vector by normal matrix [page:Matrix3 m] and normalizes the result.

[method:this applyQuaternion]( [param:Quaternion quaternion] )

Applies a [page:Quaternion] transform to this vector.

[method:Float angleTo]( [param:Vector3 v] )

Returns the angle between this vector and vector [page:Vector3 v] in radians.

[method:this ceil]()

The [page:.x x], [page:.y y] and [page:.z z] components of this vector are rounded up to the nearest integer value.

[method:this clamp]( [param:Vector3 min], [param:Vector3 max] )

[page:Vector3 min] - the minimum [page:.x x], [page:.y y] and [page:.z z] values.
[page:Vector3 max] - the maximum [page:.x x], [page:.y y] and [page:.z z] values in the desired range

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.

[method:this clampLength]( [param:Float min], [param:Float max] )

[page:Float min] - the minimum value the length will be clamped to
[page:Float max] - the maximum value the length will be clamped to

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.

[method:this clampScalar]( [param:Float min], [param:Float max] )

[page:Float min] - the minimum value the components will be clamped to
[page:Float max] - the maximum value the components will be clamped to

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.

[method:Vector3 clone]()

Returns a new vector3 with the same [page:.x x], [page:.y y] and [page:.z z] values as this one.

[method:this copy]( [param:Vector3 v] )

Copies the values of the passed vector3's [page:.x x], [page:.y y] and [page:.z z] properties to this vector3.

[method:this cross]( [param:Vector3 v] )

Sets this vector to [link:https://en.wikipedia.org/wiki/Cross_product cross product] of itself and [page:Vector3 v].

[method:this crossVectors]( [param:Vector3 a], [param:Vector3 b] )

Sets this vector to [link:https://en.wikipedia.org/wiki/Cross_product cross product] of [page:Vector3 a] and [page:Vector3 b].

[method:Float distanceTo]( [param:Vector3 v] )

Computes the distance from this vector to [page:Vector3 v].

[method:Float manhattanDistanceTo]( [param:Vector3 v] )

Computes the [link:https://en.wikipedia.org/wiki/Taxicab_geometry Manhattan distance] from this vector to [page:Vector3 v].

[method:Float distanceToSquared]( [param:Vector3 v] )

Computes the squared distance from this vector to [page:Vector3 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.

[method:this divide]( [param:Vector3 v] )

Divides this vector by [page:Vector3 v].

[method:this divideScalar]( [param:Float s] )

Divides this vector by scalar [page:Float s].

[method:Float dot]( [param:Vector3 v] )

Calculate the [link:https://en.wikipedia.org/wiki/Dot_product dot product] of this vector and [page:Vector3 v].

[method:Boolean equals]( [param:Vector3 v] )

Returns `true` if the components of this vector and [page:Vector3 v] are strictly equal; `false` otherwise.

[method:this floor]()

The components of this vector are rounded down to the nearest integer value.

[method:this fromArray]( [param:Array array], [param:Integer offset] )

[page:Array array] - the source array.
[page:Integer offset] - ( optional) offset into the array. Default is 0.

Sets this vector's [page:.x x] value to be `array[ offset + 0 ]`, [page:.y y] value to be `array[ offset + 1 ]` and [page:.z z] value to be `array[ offset + 2 ]`.

[method:this fromBufferAttribute]( [param:BufferAttribute attribute], [param:Integer index] )

[page:BufferAttribute attribute] - the source attribute.
[page:Integer index] - index in the attribute.

Sets this vector's [page:.x x], [page:.y y] and [page:.z z] values from the [page:BufferAttribute attribute].

[method:Float getComponent]( [param:Integer index] )

[page:Integer index] - `0`, `1` or `2`.

If index equals `0` returns the [page:.x x] value.
If index equals `1` returns the [page:.y y] value.
If index equals `2` returns the [page:.z z] value.

[method:Float length]()

Computes the [link:https://en.wikipedia.org/wiki/Euclidean_distance Euclidean length] (straight-line length) from (0, 0, 0) to (x, y, z).

[method:Float manhattanLength]()

Computes the [link:http://en.wikipedia.org/wiki/Taxicab_geometry Manhattan length] of this vector.

[method:Float lengthSq]()

Computes the square of the [link:https://en.wikipedia.org/wiki/Euclidean_distance 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.

[method:this lerp]( [param:Vector3 v], [param:Float alpha] )

[page:Vector3 v] - [page:Vector3] to interpolate towards.
[page:Float alpha] - interpolation factor, typically in the closed interval `[0, 1]`.

Linearly interpolate between this vector and [page:Vector3 v], where alpha is the percent distance along the line - alpha = 0 will be this vector, and alpha = 1 will be [page:Vector3 v].

[method:this lerpVectors]( [param:Vector3 v1], [param:Vector3 v2], [param:Float alpha] )

[page:Vector3 v1] - the starting [page:Vector3].
[page:Vector3 v2] - [page:Vector3] to interpolate towards.
[page:Float alpha] - interpolation factor, typically in the closed interval `[0, 1]`.

Sets this vector to be the vector linearly interpolated between [page:Vector3 v1] and [page:Vector3 v2] where alpha is the percent distance along the line connecting the two vectors - alpha = 0 will be [page:Vector3 v1], and alpha = 1 will be [page:Vector3 v2].

[method:this max]( [param:Vector3 v] )

If this vector's x, y or z value is less than [page:Vector3 v]'s x, y or z value, replace that value with the corresponding max value.

[method:this min]( [param:Vector3 v] )

If this vector's x, y or z value is greater than [page:Vector3 v]'s x, y or z value, replace that value with the corresponding min value.

[method:this multiply]( [param:Vector3 v] )

Multiplies this vector by [page:Vector3 v].

[method:this multiplyScalar]( [param:Float s] )

Multiplies this vector by scalar [page:Float s].

[method:this multiplyVectors]( [param:Vector3 a], [param:Vector3 b] )

Sets this vector equal to [page:Vector3 a] * [page:Vector3 b], component-wise.

[method:this negate]()

Inverts this vector - i.e. sets x = -x, y = -y and z = -z.

[method:this normalize]()

Convert this vector to a [link:https://en.wikipedia.org/wiki/Unit_vector unit vector] - that is, sets it equal to a vector with the same direction as this one, but [page:.length length] 1.

[method:this project]( [param:Camera camera] )

[page:Camera camera] — camera to use in the projection.

Projects this vector from world space into the camera's normalized device coordinate (NDC) space.

[method:this projectOnPlane]( [param:Vector3 planeNormal] )

[page:Vector3 planeNormal] - A vector representing a plane normal.

[link:https://en.wikipedia.org/wiki/Vector_projection Projects] this vector onto a plane by subtracting this vector projected onto the plane's normal from this vector.

[method:this projectOnVector]( [param:Vector3 v] )

[link:https://en.wikipedia.org/wiki/Vector_projection Projects] this vector onto [page:Vector3 v].

[method:this reflect]( [param:Vector3 normal] )

[page:Vector3 normal] - the normal to the reflecting plane

Reflect this vector off of plane orthogonal to [page:Vector3 normal]. Normal is assumed to have unit length.

[method:this round]()

The components of this vector are rounded to the nearest integer value.

[method:this roundToZero]()

The components of this vector are rounded towards zero (up if negative, down if positive) to an integer value.

[method:this set]( [param:Float x], [param:Float y], [param:Float z] )

Sets the [page:.x x], [page:.y y] and [page:.z z] components of this vector.

[method:this setComponent]( [param:Integer index], [param:Float value] )

[page:Integer index] - `0`, `1` or `2`.
[page:Float value] - [page:Float]

If index equals `0` set [page:.x x] to [page:Float value].
If index equals `1` set [page:.y y] to [page:Float value].
If index equals `2` set [page:.z z] to [page:Float value]

[method:this setFromColor]( [param:Color color] )

Sets this vector's [page:.x x], [page:.y y] and [page:.z z] components from the r, g, and b components of the specified [page:Color color].

[method:this setFromCylindrical]( [param:Cylindrical c] )

Sets this vector from the cylindrical coordinates [page:Cylindrical c].

[method:this setFromCylindricalCoords]( [param:Float radius], [param:Float theta], [param:Float y] )

Sets this vector from the cylindrical coordinates [page:Cylindrical radius], [page:Cylindrical theta] and [page:Cylindrical y].

[method:this setFromEuler]( [param:Euler euler] )

Sets this vector's [page:.x x], [page:.y y] and [page:.z z] components from the x, y, and z components of the specified [page:Euler Euler Angle].

[method:this setFromMatrixColumn]( [param:Matrix4 matrix], [param:Integer index] )

Sets this vector's [page:.x x], [page:.y y] and [page:.z z] components from [page:Integer index] column of [page:Matrix4 matrix].

[method:this setFromMatrix3Column]( [param:Matrix3 matrix], [param:Integer index] )

Sets this vector's [page:.x x], [page:.y y] and [page:.z z] components from [page:Integer index] column of [page:Matrix3 matrix].

[method:this setFromMatrixPosition]( [param:Matrix4 m] )

Sets this vector to the position elements of the [link:https://en.wikipedia.org/wiki/Transformation_matrix transformation matrix] [page:Matrix4 m].

[method:this setFromMatrixScale]( [param:Matrix4 m] )

Sets this vector to the scale elements of the [link:https://en.wikipedia.org/wiki/Transformation_matrix transformation matrix] [page:Matrix4 m].

[method:this setFromSpherical]( [param:Spherical s] )

Sets this vector from the spherical coordinates [page:Spherical s].

[method:this setFromSphericalCoords]( [param:Float radius], [param:Float phi], [param:Float theta] )

Sets this vector from the spherical coordinates [page:Spherical radius], [page:Spherical phi] and [page:Spherical theta].

[method:this setLength]( [param:Float l] )

Set this vector to a vector with the same direction as this one, but [page:.length length] [page:Float l].

[method:this setScalar]( [param:Float scalar] )

Set the [page:.x x], [page:.y y] and [page:.z z] values of this vector both equal to [page:Float scalar].

[method:this setX]( [param:Float x] )

Replace this vector's [page:.x x] value with [page:Float x].

[method:this setY]( [param:Float y] )

Replace this vector's [page:.y y] value with [page:Float y].

[method:this setZ]( [param:Float z] )

Replace this vector's [page:.z z] value with [page:Float z].

[method:this sub]( [param:Vector3 v] )

Subtracts [page:Vector3 v] from this vector.

[method:this subScalar]( [param:Float s] )

Subtracts [page:Float s] from this vector's [page:.x x], [page:.y y] and [page:.z z] components.

[method:this subVectors]( [param:Vector3 a], [param:Vector3 b] )

Sets this vector to [page:Vector3 a] - [page:Vector3 b].

[method:Array toArray]( [param:Array array], [param:Integer offset] )

[page:Array array] - (optional) array to store this vector to. If this is not provided a new array will be created.
[page:Integer offset] - (optional) optional offset into the array.

Returns an array [x, y, z], or copies x, y and z into the provided [page:Array array].

[method:this transformDirection]( [param:Matrix4 m] )

Transforms the direction of this vector by a matrix (the upper left 3 x 3 subset of a [page:Matrix4 m]) and then [page:.normalize normalizes] the result.

[method:this unproject]( [param:Camera camera] )

[page:Camera camera] — camera to use in the projection.

Projects this vector from the camera's normalized device coordinate (NDC) space into world space.

[method:this random]()

Sets each component of this vector to a pseudo-random value between `0` and `1`, excluding `1`.

[method:this randomDirection]()

Sets this vector to a uniformly random point on a unit sphere.

Source

[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]