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
00023 #define CS_POLY_IN 1
00024 #define CS_POLY_ON 0
00025 #define CS_POLY_OUT -1
00026
00027 #include "csgeom/vector2.h"
00028 #include "csgeom/segment.h"
00029
00030 class csPoly2D;
00031
00037 class csPlane2
00038 {
00039 public:
00041 csVector2 norm;
00042
00044 float CC;
00045
00047 csPlane2 () : norm (0,1), CC (0) {}
00048
00050 csPlane2 (const csVector2& plane_norm, float c=0) : norm (plane_norm), CC (c) {}
00051
00053 csPlane2 (float a, float b, float c=0) : norm (a,b), CC (c) {}
00054
00056 inline void Set (const csVector2& v1, const csVector2& v2)
00057 {
00058 norm.x = v2.y-v1.y;
00059 norm.y = -(v2.x-v1.x);
00060 CC = - (v2 * norm);
00061 }
00062
00064 inline void Set (const csSegment2& s)
00065 {
00066 Set (s.Start (), s.End ());
00067 }
00068
00070 csPlane2 (const csVector2& v1, const csVector2& v2)
00071 {
00072 Set (v1, v2);
00073 }
00074
00076 csPlane2 (const csSegment2& s)
00077 {
00078 Set (s);
00079 }
00080
00082 inline csVector2& Normal () { return norm; }
00083
00085 inline csVector2 GetNormal () const { return norm; }
00086
00088 inline float A () const { return norm.x; }
00090 inline float B () const { return norm.y; }
00092 inline float C () const { return CC; }
00093
00095 inline float& A () { return norm.x; }
00097 inline float& B () { return norm.y; }
00099 inline float& C () { return CC; }
00100
00102 inline void Set (float a, float b, float c)
00103 { norm.x = a; norm.y = b; CC = c; }
00104
00106 inline float Classify (const csVector2& pt) const { return norm*pt+CC; }
00107
00109 static float Classify (float A, float B, float C,
00110 const csVector2& pt)
00111 { return A*pt.x + B*pt.y + C; }
00112
00118 inline float Distance (const csVector2& pt) const
00119 { return ABS (Classify (pt)); }
00120
00127 inline float SquaredDistance (const csVector2& pt) const
00128 {
00129 return Classify (pt) / norm.SquaredNorm ();
00130 }
00131
00133 void Invert () { norm = -norm; CC = -CC; }
00134
00136 void Normalize ()
00137 {
00138 float f = norm.Norm ();
00139 if (f) { norm /= f; CC /= f; }
00140 }
00141 };
00142
00143 #endif // __CS_PLANE2_H__