Morph-SynRJ
view mth_plane3.h @ 0:22de913c2d84
morph-synrj intro
| author | "Cedric Pinson <cedric.pinson@alcove.fr> <mornifle@plopbyte.net>" |
|---|---|
| date | Tue Nov 27 15:23:52 2007 +0100 (2007-11-27) |
| parents | |
| children |
line source
1 /** @file mth_plane3.h
2 *
3 * @brief Oriented plane
4 *
5 *****************************************************************************
6 *
7 * @author Cedric Pinson
8 *
9 * @date Created 2001/08
10 *
11 * @version $Id: mth_plane3.h,v 1.1 2004/01/09 21:41:22 mryoung Exp $
12 *
13 ****************************************************************************/
15 #ifndef MTH_PLANE3_H
16 #define MTH_PLANE3_H
18 #include "mth_vector3.h"
22 /** Oriented plane
23 *
24 * An oriented plane is described by a normal and a signed distance to the
25 * origin with respect to this normal.
26 *
27 */
28 namespace mth {
30 struct Plane3_t {
32 /// Normal of plane
33 Vector3_t normal;
35 /// position on axis
36 float pos;
39 /** Default constructor*/
40 Plane3_t() { }
43 /** Initialize a plane with a normal and a signed position*/
44 Plane3_t(const Vector3_t& n, const float p) : normal(n), pos(p) { }
48 Plane3_t(const Plane3_t& v)
49 { normal=v.normal; pos=v.pos; }
52 /** Initialise a plane passing through three points v, v1 and v2
53 *
54 * @param v point to pass through
55 * @param v1 point to pass through
56 * @param v2 point to pass through
57 *
58 * @return 0 if no error, -1 if the plane could not be determined
59 *
60 */
61 int Init(const Vector3_t& v, const Vector3_t& v1, const Vector3_t& v2) {
62 normal = (v1-v).Cross((v2-v));
63 if (normal.Normalize() < 0) return -1;
64 pos = v.Dot(normal);
65 return 0;
66 }
69 /** Initialize a plane with a normal and a signed position*/
70 void Init(const Vector3_t& n, const float p) { normal=n; pos=p; }
73 /** Initialize a plane with a normal and a signed position*/
74 void Init(const Plane3_t& n) { normal=n.normal; pos=n.pos; }
78 /** Initialize a plane with a normal and a vector*/
79 void Init(const Vector3_t& n, const Vector3_t &p) { normal=n; pos=n*p ; }
83 /** Constructor from three points*/
84 Plane3_t(const Vector3_t& v, const Vector3_t& v1, const Vector3_t& v2) {
85 Init(v, v1, v2);
86 }
89 /** Return the signed distance of a point from the plane.
90 *
91 * @param p Point to test
92 *
93 * @return positive if in the front half space, negative otherwise.
94 *
95 */
96 float Dist(const Vector3_t& p) const {
97 return p.Dot(normal) - pos; }
100 /// Return normal
101 const Vector3_t& Direction() const { return normal;}
103 /// Return position on axis
104 const float& Position() const { return pos;}
107 /** unari minus operator*/
108 const Plane3_t operator - () const {
109 return Plane3_t(-normal, -pos); }
112 /** operator translation*/
113 const Plane3_t operator + (const Vector3_t & v) const {
114 return Plane3_t(normal, pos + v.Dot(normal));
115 }
118 /** operator translation inverse*/
119 const Plane3_t operator - (const Vector3_t & v) const {
120 return Plane3_t(normal, pos - v.Dot(normal));
121 }
123 };
125 }
126 #endif
