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.

18 lines (17 loc) 588 B
import { dot4D } from "./dot-4d.js"; /** * Reflects a 4D vector across a normal vector. * The normal vector should be normalized (unit length). * @param {ArrayVector4D} xyzw - Vector as `[x, y, z, w]` * @param {ArrayVector4D} normal - Normal vector (must be normalized) * @returns {ArrayVector4D} The reflected vector */ export const reflect4D = (xyzw, normal) => { const dot = dot4D(xyzw, normal); return [ xyzw[0] - 2 * dot * normal[0], xyzw[1] - 2 * dot * normal[1], xyzw[2] - 2 * dot * normal[2], xyzw[3] - 2 * dot * normal[3], ]; };