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.

13 lines (12 loc) 535 B
import { dot3D } from "./dot-3d.js"; /** * Reflects a vector across a normal vector. * The normal vector should be normalized (unit length). * @param {ArrayVector3D} xyz - Vector as `[x, y, z]` to reflect * @param {ArrayVector3D} normal - Normal vector to reflect across (must be normalized) * @returns {ArrayVector3D} The reflected vector */ export const reflect3D = (xyz, normal) => { const dot = dot3D(xyz, normal); return [xyz[0] - 2 * dot * normal[0], xyz[1] - 2 * dot * normal[1], xyz[2] - 2 * dot * normal[2]]; };