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.

18 lines (17 loc) 925 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.project3D = void 0; const magnitude_3d_js_1 = require("./magnitude-3d.js"); /** * Projects one 3D vector onto the second. * @param {ArrayVector3D} xyz1 - Vector to project * @param {ArrayVector3D} xyz2 - Vector to project onto * @param {number} [m1] - Optional magnitude of the vector to project (default: `magnitude3D(xyz1)`) * @param {number} [m2] - Optional magnitude of the vector to project onto (default: `magnitude3D(xyz2)`) * @returns {ArrayVector3D} The projected vector */ const project3D = (xyz1, xyz2, m1 = (0, magnitude_3d_js_1.magnitude3D)(xyz1), m2 = (0, magnitude_3d_js_1.magnitude3D)(xyz2)) => { const f = m1 * Math.cos(Math.acos((xyz1[0] * xyz2[0] + xyz1[1] * xyz2[1] + xyz1[2] * xyz2[2]) / (m1 * m2))); return [(xyz2[0] / m2) * f, (xyz2[1] / m2) * f, (xyz2[2] / m2) * f]; }; exports.project3D = project3D;