[name]

Class representing a 4D [link:https://en.wikipedia.org/wiki/Vector_space vector]. A 4D vector is an ordered quadruplet of numbers (labeled x, y, z, and w), which can be used to represent a number of things, such as:

There are other things a 4D vector can be used to represent, however these are the most common uses in three.js.

Iterating through a Vector4 instance will yield its components (x, y, z, w) in the corresponding order.

Code Example

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

Constructor

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

[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*.
[page:Float w] - the w value of this vector. Default is *1*.

Creates a new [name].

Properties

[property:Float x]

[property:Float y]

[property:Float z]

[property:Float w]

[property:Float width]

Alias for [page:.z z].

[property:Float height]

Alias for [page:.w w].

Methods

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

Adds [page:Vector4 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], [page:.z z] and [page:.w w] values.

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

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

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

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

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

Multiplies this vector by 4 x 4 [page:Matrix4 m].

[method:this ceil]()

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

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

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

If this vector's x, y, z or w value is greater than the max vector's x, y, z or w value, it is replaced by the corresponding value.

If this vector's x, y, z or w value is less than the min vector's x, y, z or w 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, it is replaced by the max value.

If this vector's length is less than the min value, it is replaced by 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, z or w values are greater than the max value, they are replaced by the max value.

If this vector's x, y, z or w values are less than the min value, they are replaced by the min value.

[method:Vector4 clone]()

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

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

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

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

Divides this vector by scalar [page:Float s].
Sets vector to *( 0, 0, 0, 0 )* if *[page:Float s] = 0*.

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

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

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

Returns *true* if the components of this vector and [page:Vector4 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 ] [page:.z z] value to be array[ offset + 2 ] and [page:.w w ] value to be array[ offset + 3 ].

[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], [page:.z z] and [page:.w w] values from the [page:BufferAttribute attribute].

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

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

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.
If index equals 3 returns the [page:.w w] value.

[method:Float length]()

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

[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, 0) to (x, y, z, w). 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:Vector4 v], [param:Float alpha] )

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

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

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

[page:Vector4 v1] - the starting [page:Vector4].
[page:Vector4 v2] - [page:Vector4] 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:Vector4 v1] and [page:Vector4 v2] where alpha is the percent distance along the line connecting the two vectors - alpha = 0 will be [page:Vector4 v1], and alpha = 1 will be [page:Vector4 v2].

[method:this negate]()

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

[method:this normalize]()

Converts 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 max]( [param:Vector4 v] )

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

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

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

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

Multiplies this vector by [page:Vector4 v].

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

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

[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], [param:Float w] )

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

[method:this setAxisAngleFromQuaternion]( [param:Quaterion q] )

[page:Quaterion q] - a normalized [page:Quaterion]

Sets the [page:.x x], [page:.y y] and [page:.z z] components of this vector to the quaternion's axis and [page:.w w] to the angle.

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

[page:Matrix4 m] - a [page:Matrix4] of which the upper left 3x3 matrix is a pure rotation matrix.

Sets the [page:.x x], [page:.y y] and [page:.z z] to the axis of rotation and [page:.w w] to the angle.

[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].
If index equals 3 set [page:.w w] to [page:Float value].

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

Sets 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] )

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

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

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

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

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

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

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

[method:this setW]( [param:Float w] )

Replaces this vector's [page:.w w] value with [page:Float w].

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

Subtracts [page:Vector4 v] from this vector.

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

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

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

Sets this vector to [page:Vector4 a] - [page:Vector4 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, w], or copies x, y, z and w into the provided [page:Array array].

[method:this random]()

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

Source

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