00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __CS_PLANE2_H__
00021 #define __CS_PLANE2_H__
00022
00029 #define CS_POLY_IN 1
00030 #define CS_POLY_ON 0
00031 #define CS_POLY_OUT -1
00032
00033 #include "csgeom/vector2.h"
00034 #include "csgeom/segment.h"
00035
00036 class csPoly2D;
00037
00043 class csPlane2
00044 {
00045 public:
00047 csVector2 norm;
00048
00050 float CC;
00051
00053 csPlane2 () : norm (0,1), CC (0) {}
00054
00056 csPlane2 (const csVector2& plane_norm, float c=0) : norm (plane_norm), CC (c) {}
00057
00059 csPlane2 (float a, float b, float c=0) : norm (a,b), CC (c) {}
00060
00062 inline void Set (const csVector2& v1, const csVector2& v2)
00063 {
00064 norm.x = v2.y-v1.y;
00065 norm.y = -(v2.x-v1.x);
00066 CC = - (v2 * norm);
00067 }
00068
00070 inline void Set (const csSegment2& s)
00071 {
00072 Set (s.Start (), s.End ());
00073 }
00074
00076 csPlane2 (const csVector2& v1, const csVector2& v2)
00077 {
00078 Set (v1, v2);
00079 }
00080
00082 csPlane2 (const csSegment2& s)
00083 {
00084 Set (s);
00085 }
00086
00088 inline csVector2& Normal () { return norm; }
00089
00091 inline csVector2 GetNormal () const { return norm; }
00092
00094 inline float A () const { return norm.x; }
00096 inline float B () const { return norm.y; }
00098 inline float C () const { return CC; }
00099
00101 inline float& A () { return norm.x; }
00103 inline float& B () { return norm.y; }
00105 inline float& C () { return CC; }
00106
00108 inline void Set (float a, float b, float c)
00109 { norm.x = a; norm.y = b; CC = c; }
00110
00112 inline float Classify (const csVector2& pt) const { return norm*pt+CC; }
00113
00115 static float Classify (float A, float B, float C,
00116 const csVector2& pt)
00117 { return A*pt.x + B*pt.y + C; }
00118
00124 inline float Distance (const csVector2& pt) const
00125 { return ABS (Classify (pt)); }
00126
00133 inline float SquaredDistance (const csVector2& pt) const
00134 {
00135 return Classify (pt) / norm.SquaredNorm ();
00136 }
00137
00139 void Invert () { norm = -norm; CC = -CC; }
00140
00142 void Normalize ()
00143 {
00144 float f = norm.Norm ();
00145 if (f) { norm /= f; CC /= f; }
00146 }
00147 };
00148
00151 #endif // __CS_PLANE2_H__