Alias for y.
Alias for x.
Add v to this vector.
Input one 2d vector
Return this vector
Add the multiple of v and s to this vector.
Input one 2d vector
Input one scalar value
Return this vector
Set this vector to a + b.
Input one 2d vector
Input one 2d vector
Return this vector
Return the angle between this vector and vector v in radians.
Input one 2d vector
Return the angle between this vector and vector v in radians.
Multiply this vector (with an implicit 1 as the 3rd component) by m.
Input one 3x3 matrix
Return this vector
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.
Input the minimum x and y values
Input the maximum x and y values in the desired range
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.
Input the minimum value the length will be clamped to
Input the maximum value the length will be clamped to
Return this vector
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.
Input the minimum value the components will be clamped to
Input the maximum value the length will be clamped to
Return this vector
Return a new 2d vector with the same x and y values as this one.
Return the cloned vector
Copy the values of the passed vector's x and y properties to this vector.
Input one 2d vector
Return this vector
Calculate 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.
Input one 2d vector
Return the cross product of this vector and v.
Compute the distance from this vector to v.
Input one 2d vector
Return the distance from this vector to v.
Compute 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.
Input one 2d vector
Return the squared distance from this vector to v.
Divide this vector by v.
Input one 2d vector
Return this vector
Calculate the dot product of this vector and v.
Input one 2d vector
Return the dot product of this vector and v.
Return true if the components of this vector and v are strictly equal; false otherwise.
Input one 2d vector to compare
Return true if the components of this vector and v are strictly equal; false otherwise.
Compute 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.
Return the square of the Euclidean length (straight-line length) from (0, 0) to (x, y)
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.
Input 2d vector to interpolate towards.
Input interpolation factor, typically in the closed interval [0, 1].
Return this vector
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.
Input the starting vector.
Input vector to interpolate towards.
Input interpolation factor, typically in the closed interval [0, 1].
Compute the Manhattan distance from this vector to v.
Input one 2d vector
Return the Manhattan distance from this vector to v.
If this vector's x or y value is less than v's x or y value, replace that value with the corresponding max value.
Input one 2d vector
Return this vector
If this vector's x or y value is greater than v's x or y value, replace that value with the corresponding min value.
Input one 2d vector
Return this vector
Multiply this vector by v.
Input one 2d vector
Return this vector
Rotate this vector around center by angle radians.
Input the point around which to rotate.
Input the angle to rotate, in radians.
Return this vector
Subtract v from this vector.
Input one 2d vector
Return this vector
Sets this vector to a - b.
Input one 2d vector
Input one 2d vector
Return this vector
Return an array [x, y], or copies x and y into the provided array.
Optional
array: number[]Input (optional) array to store this vector to. If this is not provided, a new array will be created.
Optional
offset: numberInput (optional) optional offset into the array.
Return an array [x, y], or copies x and y into the provided array.
The class representing a 2d vector.