modeling/src/maths/plane/projectionOfPoint.js

  1. const vec3 = require('../vec3')
  2. /**
  3. * Project the given point on to the given plane.
  4. *
  5. * @param {plane} plane - plane of reference
  6. * @param {vec3} point - point of reference
  7. * @return {vec3} projected point on plane
  8. * @alias module:modeling/maths/plane.projectionOfPoint
  9. */
  10. const projectionOfPoint = (plane, point) => {
  11. const a = point[0] * plane[0] + point[1] * plane[1] + point[2] * plane[2] - plane[3]
  12. const x = point[0] - a * plane[0]
  13. const y = point[1] - a * plane[1]
  14. const z = point[2] - a * plane[2]
  15. return vec3.fromValues(x, y, z)
  16. }
  17. module.exports = projectionOfPoint