* Rotates a 2D vector by an angle without changing its magnitude. * * By convention, the positive x-axis has an angle of 0. Angles increase in * the clockwise direction. * * If the vector was created with * createVector() , `rotate()` uses * the un
(a)
| 2164 | * } |
| 2165 | */ |
| 2166 | rotate(a) { |
| 2167 | let newHeading = this.heading() + a; |
| 2168 | if (this.isPInst) newHeading = this._toRadians(newHeading); |
| 2169 | const mag = this.mag(); |
| 2170 | this.x = Math.cos(newHeading) * mag; |
| 2171 | this.y = Math.sin(newHeading) * mag; |
| 2172 | return this; |
| 2173 | } |
| 2174 | |
| 2175 | /** |
| 2176 | * Calculates the angle between two vectors. |
no test coverage detected