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) 876 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.project2D = void 0; const magnitude_2d_js_1 = require("./magnitude-2d.js"); /** * Projects one 2D vector onto another. * @param {ArrayVector2D} xy1 - Vector to project * @param {ArrayVector2D} xy2 - Vector to project onto * @param {number} [m1] - Optional magnitude of the first vector (default: `magnitude2D(xy1)`) * @param {number} [m2] - Optional magnitude of the second vector (default: `magnitude2D(xy2)`) * @returns {ArrayVector2D} The projected vector */ const project2D = (xy1, xy2, m1 = (0, magnitude_2d_js_1.magnitude2D)(xy1), m2 = (0, magnitude_2d_js_1.magnitude2D)(xy2)) => { const f = m1 * Math.cos(Math.atan2(xy1[0] * xy2[1] - xy1[1] * xy2[0], xy1[0] * xy2[0] + xy1[1] * xy2[1])); return [(xy2[0] / m2) * f, (xy2[1] / m2) * f]; }; exports.project2D = project2D;