Constructor
new Vector(x, y)
Parameters:
| Name | Type | Description |
|---|---|---|
x |
Number | the x component of the vector |
y |
Number | the y component of the vector |
Members
angle
the angle of the vector
isZeroVector
whether the vector is a zero vector or not
magnitude
the magnitude of the vector
slope
the slope of the vector, calculated by y/x
unitVector
the unit vector of the given vector
Methods
flipX() → {Vector}
flip the vector horizontally, update is made to the original vector
Returns:
the flipped vector
- Type
- Vector
flipY() → {Vector}
flip the vector horizontally, update is made to the original vector
Returns:
the flipped vector
- Type
- Vector
negative() → {Vector}
the negative of the vector
Returns:
the flipped vector
- Type
- Vector
rotate(angle) → {Vector}
rotate the vector by the given degree, update is made to the original vector
Parameters:
| Name | Type | Description |
|---|---|---|
angle |
Number | the angle to rotate in radian |
Returns:
the rotated vector
- Type
- Vector
scale(factor) → {Vector}
scale the vector by the given scale factor
Parameters:
| Name | Type | Description |
|---|---|---|
factor |
Number | the scale factor |
Returns:
the scaled vector
- Type
- Vector
scaleX(factor) → {Vector}
scale the vector in the x-direction only by the given scale factor
Parameters:
| Name | Type | Description |
|---|---|---|
factor |
Number | the scale factor |
Returns:
the scaled vector
- Type
- Vector
scaleY(factor) → {Vector}
scale the vector in the y-direction only by the given scale factor
Parameters:
| Name | Type | Description |
|---|---|---|
factor |
Number | the scale factor |
Returns:
the scaled vector
- Type
- Vector