Constructor
new Vector(x, y)
Set initial values for (x, y); defaults to (0, 0).
Parameters:
Name | Type | Default | Description |
---|---|---|---|
x |
number | 0 | the x coordinate |
y |
number | 0 | the y coordinate |
Methods
addValues(dx, dy)
Add values to the x and y coordinates.
Parameters:
Name | Type | Description |
---|---|---|
dx |
number | value to add to the x coordinate |
dy |
number | value to add to the y coordinate |
addVector(other)
Add x and y components of another vector to this vector.
Parameters:
Name | Type | Description |
---|---|---|
other |
Vector | vector to be added to this vector |
getAngle() → {number}
Get the angle (in degrees) between this vector and the positive x-axis.
(Angles increase in clockwise direction, since positive y-axis is down.)
(Angles increase in clockwise direction, since positive y-axis is down.)
Returns:
angle between this vector and positive x-axis
- Type
- number
getLength() → {number}
Get the length of this vector.
Returns:
the length of this vector
- Type
- number
multiply(value)
Multiple x and y components of this vector by a constant.
Parameters:
Name | Type | Description |
---|---|---|
value |
number | value to multiply by |
setAngle(angleDegrees)
Set the angle (in degrees) between this vector and the positive x-axis
(without changing the current length).
(Angles increase in clockwise direction, since positive y-axis is down.)
(Angles increase in clockwise direction, since positive y-axis is down.)
Parameters:
Name | Type | Description |
---|---|---|
angleDegrees |
number | the new direction angle of this vector |
setLength(length)
Set the length of this vector (without changing the current direction).
Parameters:
Name | Type | Description |
---|---|---|
length |
number | new length of this vector |
setValues(x, y)
Set new values for the x and y coordinates.
Parameters:
Name | Type | Description |
---|---|---|
x |
number | new x coordinate |
y |
number | new y coordinate |