* Calculates the angle between two vectors. * * The angles returned are signed, which means that * `v1.angleBetween(v2) === -v2.angleBetween(v1)`. * * If the vector was created with * createVector() , `angleBetween()` returns * angles in the units
(v)
| 2297 | * } |
| 2298 | */ |
| 2299 | angleBetween(v) { |
| 2300 | const magSqMult = this.magSq() * v.magSq(); |
| 2301 | // Returns NaN if either vector is the zero vector. |
| 2302 | if (magSqMult === 0) { |
| 2303 | return NaN; |
| 2304 | } |
| 2305 | const u = this.cross(v); |
| 2306 | // The dot product computes the cos value, and the cross product computes |
| 2307 | // the sin value. Find the angle based on them. In addition, in the case of |
| 2308 | // 2D vectors, a sign is added according to the direction of the vector. |
| 2309 | let angle = Math.atan2(u.mag(), this.dot(v)) * Math.sign(u.z || 1); |
| 2310 | if (this.isPInst) { |
| 2311 | angle = this._fromRadians(angle); |
| 2312 | } |
| 2313 | return angle; |
| 2314 | } |
| 2315 | |
| 2316 | /** |
| 2317 | * Calculates new `x`, `y`, and `z` components that are proportionally the |
no test coverage detected