source: GTP/trunk/App/Demos/Vis/CHC_revisited/Plane3.h @ 2751

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