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) 499 B
import { dot2D } from "./dot-2d.js"; /** * Reflects the vector across a normal vector. * The normal vector should be normalized (unit length). * @param {ArrayVector2D} xy - Vector as `[x, y]` to reflect * @param {ArrayVector2D} normal - Normal vector to reflect across (must be normalized) * @returns {ArrayVector2D} The reflected vector */ export const reflect2D = (xy, normal) => { const dot = dot2D(xy, normal); return [xy[0] - 2 * dot * normal[0], xy[1] - 2 * dot * normal[1]]; };