home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / gems / gemsiii / pt2plane.c < prev    next >
C/C++ Source or Header  |  1992-03-17  |  836b  |  30 lines

  1. /******************************************************************************
  2.                    Signed Distance from Point to Plane
  3.                        Author: Priamos Georgiades
  4. ******************************************************************************/
  5. #include<stdio.h>
  6.  
  7. typedef struct vect3str {
  8.     float x, y, z;
  9.     } vect3;
  10. typedef struct vect4str {
  11.     float x, y, z, w;
  12.     } vect4;
  13.  
  14. #define Vect3Dot(v1, v2) ((v1).x * (v2).x + (v1).y * (v2).y + (v1).z * (v2).z)
  15.  
  16. /*
  17. Compute the distance from a point to a plane. The plane is
  18. pleq->x * X + pleq->y * Y + pleq->z * Z + pleq->w = 0.
  19. The distance is positive if on same side as the normal, otherwise negative.
  20. Assume the plane normal to be of unit length.
  21. */
  22. float Pt2Plane(vect3 *pt, vect4 *pleq)
  23. {
  24. float dist;
  25.  
  26. dist = Vect3Dot(*pleq, *pt) + pleq->w;
  27. return(dist);
  28. }
  29.  
  30.