Constructor
new Vector2D(x, y)
Creates a Vector
Parameters:
Name | Type | Description |
---|---|---|
x |
number | The x axis scalar of the vector |
y |
number | The y axis scalar of the vector |
Extends
Members
magnitude
Gets the euclidean distance (length) of this vector
magnitude
Rescales this vector to a new magnitude
radian
Converts to this vector to angular vector notation
radian
Converts this vector from angular vector notation
x
Gets the x coordinate of this point
y
Gets the x coordinate of this point
Methods
copy(point)
Copies the values of another point to this one
Parameters:
Name | Type | Description |
---|---|---|
point |
Object | The point to copy to this one |
- Overrides:
- Source:
distanceTo(point) → {number}
Calculates the distance between two points
Parameters:
Name | Type | Description |
---|---|---|
point |
Object | The point to measure distance to |
- Overrides:
- Source:
Returns:
The distance between this point and the one passed
- Type
- number
normalize()
Normaizes this vector. A normalized vector is one with a magnitude of 1.
rotate(x, y, direction)
Rotates this vector by another vector in a given direction
Parameters:
Name | Type | Description |
---|---|---|
x |
number | The x scalar of the vector to rotate by |
y |
number | The y scalar of the vector to rotate by |
direction |
number | 1 to rotate clockwise, -1 to rotate anti-clockwise |
rotateByRadians(radians)
Rotates this vector clockwise by an angle in radians
Parameters:
Name | Type | Description |
---|---|---|
radians |
number | The angle to rotate by in radians |
rotateByVector(vector)
Rotates this vector clockwise by another vector
Parameters:
Name | Type | Description |
---|---|---|
vector |
number | The vector to rotate by |
unrotateByRadians(radians)
Rotates this vector anti-clockwise by an angle in radians
Parameters:
Name | Type | Description |
---|---|---|
radians |
number | The angle to rotate by in radians |
unrotateByVector(vector)
Rotates this vector anti-clockwise by another vector
Parameters:
Name | Type | Description |
---|---|---|
vector |
number | The vector to rotate by |