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
00030 #ifndef __CS_POLY_MACROS__
00031 #define __CS_POLY_MACROS__
00032 #define CS_POLY_IN 1
00033 #define CS_POLY_ON 0
00034 #define CS_POLY_OUT -1
00035 #endif
00036
00037 #include "csgeom/vector2.h"
00038 #include "csgeom/segment.h"
00039
00040 class csPoly2D;
00041
00047 class csPlane2
00048 {
00049 public:
00051 csVector2 norm;
00052
00054 float CC;
00055
00057 csPlane2 () : norm (0,1), CC (0) {}
00058
00060 csPlane2 (const csVector2& plane_norm, float c=0) : norm (plane_norm), CC (c) {}
00061
00063 csPlane2 (float a, float b, float c=0) : norm (a,b), CC (c) {}
00064
00066 inline void Set (const csVector2& v1, const csVector2& v2)
00067 {
00068 norm.x = v2.y-v1.y;
00069 norm.y = -(v2.x-v1.x);
00070 CC = - (v2 * norm);
00071 }
00072
00074 inline void Set (const csSegment2& s)
00075 {
00076 Set (s.Start (), s.End ());
00077 }
00078
00080 csPlane2 (const csVector2& v1, const csVector2& v2)
00081 {
00082 Set (v1, v2);
00083 }
00084
00086 csPlane2 (const csSegment2& s)
00087 {
00088 Set (s);
00089 }
00090
00092 inline csVector2& Normal () { return norm; }
00093
00095 inline csVector2 GetNormal () const { return norm; }
00096
00098 inline float A () const { return norm.x; }
00100 inline float B () const { return norm.y; }
00102 inline float C () const { return CC; }
00103
00105 inline float& A () { return norm.x; }
00107 inline float& B () { return norm.y; }
00109 inline float& C () { return CC; }
00110
00112 inline void Set (float a, float b, float c)
00113 { norm.x = a; norm.y = b; CC = c; }
00114
00116 inline float Classify (const csVector2& pt) const { return norm*pt+CC; }
00117
00119 static float Classify (float A, float B, float C,
00120 const csVector2& pt)
00121 { return A*pt.x + B*pt.y + C; }
00122
00128 inline float Distance (const csVector2& pt) const
00129 { return ABS (Classify (pt)); }
00130
00137 inline float SquaredDistance (const csVector2& pt) const
00138 {
00139 return Classify (pt) / norm.SquaredNorm ();
00140 }
00141
00143 void Invert () { norm = -norm; CC = -CC; }
00144
00146 void Normalize ()
00147 {
00148 float f = norm.Norm ();
00149 if (f) { norm /= f; CC /= f; }
00150 }
00151 };
00152
00155 #endif // __CS_PLANE2_H__