* Vector rotation (see https://en.wikipedia.org/wiki/Rotation_matrix) * * @param angleInRadians The angle in radians by which to rotate the vector. * @returns The rotated vector.
(angleInRadians)
| 121 | * @returns The rotated vector. |
| 122 | */ |
| 123 | rotate(angleInRadians) { |
| 124 | const ca = Math.cos(angleInRadians) |
| 125 | const sa = Math.sin(angleInRadians) |
| 126 | const x = ca * this.x - sa * this.y |
| 127 | const y = sa * this.x + ca * this.y |
| 128 | return new Vector2(x, y) |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Measure angle between two vectors |