@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) • 851 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.lookAt2D = void 0;
const magnitude_2d_js_1 = require("./magnitude-2d.js");
/**
* Calculates the 2D vector angle of a vector pointing at another.
* @param {ArrayVector2D} xy1 - First vector as `[x, y]`
* @param {ArrayVector2D} xy2 - Second vector as `[x, y]` (target to look at)
* @param {number} [m1] - Optional current magnitude of the first vector (default: magnitude2D(xy1))
* @param {number} [m2] - Optional current magnitude of the second vector (default: magnitude2D(xy2))
* @returns {ArrayVector2D} Vector pointing at the target with the magnitude of xy1
*/
const lookAt2D = (xy1, xy2, m1 = (0, magnitude_2d_js_1.magnitude2D)(xy1), m2 = (0, magnitude_2d_js_1.magnitude2D)(xy2)) => [(xy2[0] / m2) * m1, (xy2[1] / m2) * m1];
exports.lookAt2D = lookAt2D;