Represents a 2D vector.
Signature:
export default class Vector2 extends Float32Array implements Vector2Like Extends: Float32Array
Implements: Vector2Like
All vector methods result in mutation of the vector instance. This class extends Float32Array to provide an efficient way to create and manipulate a 2-dimensional vector. Various convenience methods are provided for common vector operations.
|
Constructor |
Modifiers |
Description |
|---|---|---|
|
Constructs a new instance of the |
|
Property |
Modifiers |
Type |
Description |
|---|---|---|---|
|
|
number |
The length of the vector. | |
|
|
number |
The magnitude of the vector. Alias for | |
|
|
number |
The squared length of the vector. | |
|
|
number |
The squared magnitude of the vector. Alias for | |
|
number |
The x-component of the vector. | ||
|
number |
The y-component of the vector. |
|
Method |
Modifiers |
Description |
|---|---|---|
|
Adds a vector to the current vector. | ||
|
Returns the angle between two vectors. | ||
|
Rounds each component of the vector up to the nearest integer. | ||
|
Returns a new vector with the same components as the current vector. | ||
|
Copies the components of a vector to the current vector. | ||
|
|
Creates a new | |
|
Calculates the distance between the current vector and another vector. | ||
|
Divides the current vector by another vector. | ||
|
Calculates the dot product of the current vector and another vector. | ||
|
Checks if the current vector is approximately equal to another vector. | ||
|
Checks if the current vector is exactly equal to another vector. | ||
|
Rounds each component of the vector down to the nearest integer. | ||
|
Inverts the components of the current vector. | ||
|
Linearly interpolates between the current vector and another vector. | ||
|
Sets each component of the vector to the maximum of the current vector and another vector. | ||
|
Sets each component of the vector to the minimum of the current vector and another vector. | ||
|
Multiplies each component of the current vector by the corresponding component of another vector. | ||
|
Negates each component of the vector. | ||
|
Normalizes the current vector. | ||
|
Randomizes the components of the current vector. | ||
|
Rotates the current vector around an origin. | ||
|
Rounds each component of the vector to the nearest integer. | ||
|
Scales the current vector by a scalar value. | ||
|
Scales the current vector by a scalar value and adds the result to another vector. | ||
|
Subtracts a vector from the current vector. | ||
|
Returns a string representation of the vector in x,y format. | ||
|
Transforms the current vector by a matrix2. | ||
|
Transforms the current vector by a matrix3. | ||
|
Transforms the current vector by a matrix4. | ||
|
Sets each component of the vector to zero. |