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.

19 lines (18 loc) 974 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.project4D = void 0; const dot_4d_js_1 = require("./dot-4d.js"); const magnitude_4d_js_1 = require("./magnitude-4d.js"); /** * Projects one 4D vector onto another. * @param {ArrayVector4D} xyzw1 - First vector as `[x, y, z, w]` * @param {ArrayVector4D} xyzw2 - Second vector as `[x, y, z, w]` to project onto * @param {number} [m1] - Optional current magnitude (default: `magnitude4D(xyzw1)`) * @param {number} [m2] - Optional current magnitude (default: `magnitude4D(xyzw2)`) * @returns {ArrayVector4D} The projected vector */ const project4D = (xyzw1, xyzw2, m1 = (0, magnitude_4d_js_1.magnitude4D)(xyzw1), m2 = (0, magnitude_4d_js_1.magnitude4D)(xyzw2)) => { const f = m1 * Math.cos(Math.acos((0, dot_4d_js_1.dot4D)(xyzw1, xyzw2) / (m1 * m2))); return [(xyzw2[0] / m2) * f, (xyzw2[1] / m2) * f, (xyzw2[2] / m2) * f, (xyzw2[3] / m2) * f]; }; exports.project4D = project4D;