@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.
17 lines (16 loc) • 688 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.reflect3D = void 0;
const dot_3d_js_1 = require("./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
*/
const reflect3D = (xyz, normal) => {
const dot = (0, dot_3d_js_1.dot3D)(xyz, normal);
return [xyz[0] - 2 * dot * normal[0], xyz[1] - 2 * dot * normal[1], xyz[2] - 2 * dot * normal[2]];
};
exports.reflect3D = reflect3D;