source: GTP/trunk/Lib/Vis/Preprocessing/src/Plane3.h @ 860

Revision 860, 1.7 KB checked in by mattausch, 18 years ago (diff)
RevLine 
[372]1#ifndef _Plane3_H__
2#define _Plane3_H__
3
4#include "Vector3.h"
5
[860]6namespace GtpVisibilityPreprocessor {
7
[372]8 
9/** 3D Plane */
10class Plane3 {
11public:
12
13  Vector3 mNormal;
14  float mD;
15 
16  Plane3() {}
17 
18  Plane3(const Vector3 &a,
[437]19                 const Vector3 &b,
20                 const Vector3 &c
[372]21         ) {
22    Vector3 v1=a-b, v2=c-b;
23    mNormal = Normalize(CrossProd(v2,v1));
24    mD = -DotProd(b, mNormal);
25  }
26
27  Plane3(const Vector3 &normal,
[504]28                 const Vector3 &point
29                 ):mNormal(normal)
[372]30  {
31    mD = -DotProd(normal, point);
32  }
33
[396]34  void ReverseOrientation()
35  {
36          mNormal *= -1;
37          mD *= -1;
38  }
[372]39
40  float Distance(const Vector3 &v) const {
41    return DotProd(v, mNormal) + mD;
42  }
43
[697]44  enum {BACK_SIDE = -1, INTERSECTS = 0, FRONT_SIDE = 1};
45                 
46               
[639]47  /** Returns 1 if v is on front side, -1 if on back side, 0 if on plane.
48  */
49  int Side(const Vector3 &v, const float threshold = 1e-6) const;
[372]50
[437]51  /** Finds intersection of line segment between points a and b with plane.
52          @param a start point
53          @param b end point
54          @param t if not NULL, returns parameter value of intersections
55          @param coplanar if not NULL, returns true if plane and line segments are coplanar.
56  */
[372]57  Vector3 FindIntersection(const Vector3 &a,
[448]58                                                   const Vector3 &b,
59                                                   float *t = NULL,
[639]60                                                   bool *coplanar = NULL) const;
[372]61 
[437]62  /** Finds value of intersection parameter t on line segment from a to b.
[639]63      @returns 0 if coplanar, else parameter t
[437]64  */
[639]65  float FindT(const Vector3 &a, const Vector3 &b) const;
[372]66
67  friend bool
68  PlaneIntersection(const Plane3 &a, const Plane3 &b, const Plane3 &c, Vector3 &result);
69 
70  friend ostream &operator<<(ostream &s, const Plane3 p) {
71    s<<p.mNormal<<" "<<p.mD;
72    return s;
73  }
74
75 
76};
77 
78
[860]79}
[372]80
81#endif
Note: See TracBrowser for help on using the repository browser.