modeling/src/maths/plane/fromNormalAndPoint.js

  1. const vec3 = require('../vec3')
  2. /**
  3. * Represents a plane in 3D coordinate space as determined by a normal (perpendicular to the plane)
  4. * and distance from 0,0,0.
  5. *
  6. * The contents of the array are a normal [0,1,2] and a distance [3].
  7. * @see https://en.wikipedia.org/wiki/Hesse_normal_form
  8. * @typedef {Array} plane
  9. */
  10. /**
  11. * Create a new plane from the given normal and point values.
  12. *
  13. * @param {plane} out - receiving plane
  14. * @param {vec3} normal - directional vector
  15. * @param {vec3} point - origin of plane
  16. * @returns {plane} out
  17. * @alias module:modeling/maths/plane.fromNormalAndPoint
  18. */
  19. const fromNormalAndPoint = (out, normal, point) => {
  20. const u = vec3.normalize(vec3.create(), normal)
  21. const w = vec3.dot(point, u)
  22. out[0] = u[0]
  23. out[1] = u[1]
  24. out[2] = u[2]
  25. out[3] = w
  26. return out
  27. }
  28. module.exports = fromNormalAndPoint