* Find angle between 3D Coordinates * @param {Vector | number} a: Vector or Number * @param {Vector | number} b: Vector or Number * @param {Vector | number} c: Vector or Number
(a: Vector | XYZ, b: Vector | XYZ, c: Vector | XYZ)
| 389 | * @param {Vector | number} c: Vector or Number |
| 390 | */ |
| 391 | static angleBetween3DCoords(a: Vector | XYZ, b: Vector | XYZ, c: Vector | XYZ) { |
| 392 | if (!(a instanceof Vector)) { |
| 393 | a = new Vector(a); |
| 394 | b = new Vector(b); |
| 395 | c = new Vector(c); |
| 396 | } |
| 397 | // Calculate vector between points 1 and 2 |
| 398 | const v1 = (a as Vector).subtract(b as Vector); |
| 399 | |
| 400 | // Calculate vector between points 2 and 3 |
| 401 | const v2 = (c as Vector).subtract(b as Vector); |
| 402 | |
| 403 | // The dot product of vectors v1 & v2 is a function of the cosine of the |
| 404 | // angle between them (it's scaled by the product of their magnitudes). |
| 405 | const v1norm = v1.unit(); |
| 406 | const v2norm = v2.unit(); |
| 407 | |
| 408 | // Calculate the dot products of vectors v1 and v2 |
| 409 | const dotProducts = v1norm.dot(v2norm); |
| 410 | |
| 411 | // Extract the angle from the dot products |
| 412 | const angle = Math.acos(dotProducts); |
| 413 | |
| 414 | // return single angle Normalized to 1 |
| 415 | return Vector.normalizeRadians(angle); |
| 416 | } |
| 417 | /** |
| 418 | * Get normalized, spherical coordinates for the vector bc, relative to vector ab |
| 419 | * @param {Vector | number} a: Vector or Number |