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.

9 lines (8 loc) 387 B
import { magnitude3D } from "./magnitude-3d.js"; /** * Normalize a 3D vector. * @param {ArrayVector3D} xyz - Vector as `[x, y, z]` * @param {number} [m] - Optional current magnitude (default: `magnitude3D(xyz)`) * @returns {ArrayVector3D} The normalized vector */ export const normalize3D = (xyz, m = magnitude3D(xyz)) => m === 0 ? [0, 0, 0] : [xyz[0] / m, xyz[1] / m, xyz[2] / m];