MCPcopy
hub / github.com/yeemachine/kalidokit / angleBetween3DCoords

Method angleBetween3DCoords

src/utils/vector.ts:391–416  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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

Callers 2

calcArmsFunction · 0.80
solveMethod · 0.80

Calls 4

subtractMethod · 0.80
unitMethod · 0.80
dotMethod · 0.80
normalizeRadiansMethod · 0.80

Tested by

no test coverage detected