UNPKG

@fimbul-works/vec

Version:

A comprehensive TypeScript vector math library providing 2D, 3D, and 4D vector operations with a focus on performance and type safety.

15 lines (14 loc) 840 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.angleBetween3D = void 0; const magnitude_3d_js_1 = require("./magnitude-3d.js"); /** * Calculates the angle between two 3D vectors. * @param {ArrayVector3D} xyz1 - First vector as `[x, y, z]` * @param {ArrayVector3D} xyz2 - Second vector as `[x, y, z]` * @param {number} [m1] - Optional first vector magnitude (default: `magnitude3D(xyz1)`) * @param {number} [m2] - Optional second vector magnitude (default: `magnitude3D(xyz2)`) * @returns {number} Angle between the vectors in radians */ const angleBetween3D = (xyz1, xyz2, m1 = (0, magnitude_3d_js_1.magnitude3D)(xyz1), m2 = (0, magnitude_3d_js_1.magnitude3D)(xyz2)) => Math.acos((xyz1[0] * xyz2[0] + xyz1[1] * xyz2[1] + xyz1[2] * xyz2[2]) / (m1 * m2)); exports.angleBetween3D = angleBetween3D;