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.

14 lines (13 loc) 423 B
import { magnitude4D } from "./magnitude-4d.js"; /** * Normalizes a 4D vector to unit length. * @param {ArrayVector4D} xyzw - Vector as `[x, y, z, w]` * @param {number} [m] - Optional current magnitude (default: `magnitude4D(xyzw)`) * @returns {ArrayVector4D} The normalized vector */ export const normalize4D = (xyzw, m = magnitude4D(xyzw)) => [ xyzw[0] / m, xyzw[1] / m, xyzw[2] / m, xyzw[3] / m, ];