Creates a new Vector2.
(Optional) The x value of this vector. Default is 0.
(Optional) The y value of this vector. Default is 0.
Alias for y.
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 Vector2.
Alias for x.
Adds the scalar value s to this vector's x and y values.
This instance.
The scalar to add to this vector.
Sets this vector to a + b.
This instance
Computes the angle in radians of this vector with respect to the positive x-axis.
The angle (radians)
The x and y components of this vector are rounded up to the nearest integer value.
This instance.
If this vector's x or y value is greater than the max vector's x or y value, it is replaced by the corresponding value.
If this vector's x or y value is less than the min vector's x or y value, it is replaced by the corresponding value.
This instance.
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.
This instance.
The minimum value the length will be clamped to
The maximum value the length will be clamped to
If this vector's x or y values are greater than the max value, they are replaced by the max value.
If this vector's x or y values are less than the min value, they are replaced by the min value.
This instance.
the minimum value the components will be clamped to
the maximum value the components will be clamped to
Create a Vector2 with the same x and y values as this one.
A new Vector2 instance.
Calculates the cross product of this vector and v. Note that a 'cross-product' in 2D is not well-defined. This function computes a geometric cross-product often used in 2D graphics
The cross product.
The other vector.
Computes the distance from this vector to v.
The distance.
The vector to compute destance to.
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 distance squared.
The other vector.
Divides this vector by scalar s.
This instance.
Calculates the dot product of this vector and v.
The dot product.
The other vector.
Compare a vector with this vector for equality.
Returns true if the components of this vector and v are strictly equal; false otherwise.
The other vector.
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 ] and y value to be array[ offset + 1 ].
This instance.
The source array.
(Optional) Offset into the array. Default is 0.
Get the component (x or y) indicated by index parameter.
The component value
If index equals 0 returns the x value. If index equals 1 returns the y value.
Computes the Euclidean length (straight-line length) from (0, 0) to (x, y).
The length.
Computes the square of the Euclidean length (straight-line length) from (0, 0) to (x, y). If you are comparing the lengths of vectors, you should compare the length squared instead as it is slightly more efficient to calculate.
The length squared.
Linearly interpolates 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.
Vector2 to interpolate towards.
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 distance.
The other vector
Multiplies this vector by scalar s.
This instance.
The scalar to multiple this vector by.
Inverts this vector - i.e. sets x = -x and y = -y.
This instance.
Converts 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.
Set the component of this vector to random values between 0-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 and y components of this vector.
This instance.
The new x component
The new y component
Update the component value.
This instance.
If index equals 0 set x to value. If index equals 1 set y to value
The new component value
Sets this vector to a vector with the same direction as this one, but length l.
This instance.
The new length of this vector.
Sets the x and y values of this vector both equal to scalar.
This instance.
The scalar value to set.
Subtracts s from this vector's x and y components.
This instance.
The scalar to subtract from each of this vector's components.
Sets this vector to a - b.
This instance.
Returns an array [x, y], or copies x and y into the provided array.
An array.
(optional) array to store this vector to. If this is not provided, a new array will be created.
(optional) optional offset into the array.
Class representing a 2D vector. A 2D vector is an ordered pair of numbers (labeled x and y), which can be used to represent a number of things, such as:
There are other things a 2D vector can be used to represent, such as momentum vectors, complex numbers and so on. However these are the most common uses in three.js.
Iterating through a Vector2 instance will yield its components (x, y) in the corresponding order.
Example