UNPKG

@jscad/modeling

Version:

Constructive Solid Geometry (CSG) Library for JSCAD

24 lines (22 loc) 485 B
/** * Normalize the given vector. * * @param {vec3} out - receiving vector * @param {vec3} vector - vector to normalize * @returns {vec3} out * @alias module:modeling/maths/vec3.normalize */ const normalize = (out, vector) => { const x = vector[0] const y = vector[1] const z = vector[2] let len = x * x + y * y + z * z if (len > 0) { len = 1 / Math.sqrt(len) } out[0] = x * len out[1] = y * len out[2] = z * len return out } module.exports = normalize