@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.
11 lines (10 loc) • 672 B
JavaScript
import { magnitude2D } from "./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
*/
export const lookAt2D = (xy1, xy2, m1 = magnitude2D(xy1), m2 = magnitude2D(xy2)) => [(xy2[0] / m2) * m1, (xy2[1] / m2) * m1];