@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) • 747 B
JavaScript
import { magnitude3D } from "./magnitude-3d.js";
/**
* Creates a vector pointing from the first vector to the second vector, maintaining the magnitude of the first vector.
* @param {ArrayVector3D} xyz1 - First vector as `[x, y, z]` (source direction)
* @param {ArrayVector3D} xyz2 - Second vector as `[x, y, z]` (target direction)
* @param {number} [m1] - Optional current magnitude of the first vector (default: `magnitude3D(xyz1)`)
* @param {number} [m2] - Optional current magnitude of the second vector (default: `magnitude3D(xyz2)`)
* @returns {ArrayVector3D} The look-at vector
*/
export const lookAt3D = (xyz1, xyz2, m1 = magnitude3D(xyz1), m2 = magnitude3D(xyz2)) => [(xyz2[0] / m2) * m1, (xyz2[1] / m2) * m1, (xyz2[2] / m2) * m1];