home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 3 / RISC_DISC_3.iso / resources / etexts / gems / gemsv / ch7_4 / plane.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-22  |  1.5 KB  |  53 lines

  1. // -*- C++ -*-
  2. //
  3. // plane.h by George Vanecek Jr. June 1994
  4.  
  5. #ifndef _PLANE_H_
  6. #define _PLANE_H_
  7.  
  8. #ifndef _VECTOR_H_
  9. #include "vector.h"
  10. #endif
  11.  
  12. // Provide a minimal 3D plane support sufficine for the Gem.
  13. //
  14. // Any point p that is known topologically to lie on a plane pN+d~0
  15. // is included in the plane by enlarging the epsilon, so the
  16. // equation |pN+d| <= eps holds.  The point/plane relationship must
  17. // be established by the application code.
  18.  
  19. class Plane
  20. {
  21. public:
  22.   Plane ( const Counter nPoints, const Point[] );
  23.   Plane ( const Vector& v, double x ) : n(v), d(x), eps(0.0) { }
  24.   Plane ( const Plane& pl ) : n(pl.n), d(pl.d), eps(pl.eps) { }
  25.  
  26.   const Vector& normal( ) const { return n; }
  27.  
  28.   // The point is topologically known to lie in the plane, so check
  29.   // and update epsilon accordingly:
  30.   void   updateEpsilon( const Point& );
  31.   
  32.   // Signed distance from the point to the plane.
  33.   double      sDistance( const Point& p ) const { return Vector(p) * n + d; } 
  34.  
  35.   // Intersection point between this Plane and transversal line.
  36.   Point        onPoint( const Point&, const Point& ) const;
  37.  
  38.   // Which side of the plane is this point on?
  39.   Where      whichSide( const Point& ) const;
  40.  
  41. private:
  42.   Vector n;            // unit normal vector
  43.   double d;            // shortest distance from origin
  44.   double eps;            // point/plane distance epsilon
  45. };
  46.  
  47. inline Where Plane::whichSide( const Point& p ) const
  48. { const double d = sDistance( p );
  49.   return d < -eps ? BELOW : (d > eps ? ABOVE : ON);
  50. }
  51.  
  52. #endif
  53.