distancePointPlane.m 803 B

123456789101112131415161718192021222324252627282930
  1. function d = distancePointPlane(point, plane)
  2. %DISTANCEPOINTPLANE Signed distance betwen 3D point and plane.
  3. %
  4. % D = distancePointPlane(POINT, PLANE)
  5. % Returns the euclidean distance between point POINT and the plane PLANE,
  6. % given by:
  7. % POINT : [x0 y0 z0]
  8. % PLANE : [x0 y0 z0 dx1 dy1 dz1 dx2 dy2 dz2]
  9. % D : scalar
  10. %
  11. % See also:
  12. % planes3d, points3d, intersectLinePlane
  13. %
  14. % ---------
  15. % author : David Legland
  16. % INRA - TPV URPOI - BIA IMASTE
  17. % created the 18/02/2005.
  18. %
  19. % HISTORY
  20. % normalized plane normal
  21. n = normalizeVector3d(cross(plane(:,4:6), plane(:, 7:9), 2));
  22. % Uses Hessian form, ie : N.p = d
  23. % I this case, d can be found as : -N.p0, when N is normalized
  24. d = -sum(bsxfun(@times, n, bsxfun(@minus, plane(:,1:3), point)), 2);