00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00019 #ifndef __gdtgeometry__
00020 #define __gdtgeometry__
00021
00022
00023 #include<iostream>
00024 #include<math.h>
00025 #include<GDT/gdtlist.h>
00026
00027 #ifdef WIN32
00028 #define M_PI 3.14159265358979323846
00029 #endif
00030
00031 namespace gdt {
00032
00033 #define MAX(a,b) ((a)>(b) ? (a) : (b))
00034 #define MIN(a,b) ((a)<(b) ? (a) : (b))
00035
00036 #define SIGN(a) ((a>=0) ? 1 : -1)
00037
00038 class gdtpoint {
00039
00040 private:
00041
00042 double x_coord;
00043 double y_coord;
00044
00045 public:
00046
00047
00048
00049 gdtpoint();
00050
00051 gdtpoint(double x, double y);
00052
00053 ~gdtpoint();
00054
00055
00056
00057 double xcoord() const;
00058
00059 double ycoord() const;
00060
00064 double
00065 distance() const;
00066
00067
00073 double
00074 distance(gdtpoint p) const;
00075
00076
00081 gdtpoint
00082 translate (double dx, double dy) ;
00083
00084
00089 double
00090 xdist(gdtpoint q) const;
00091
00092
00098 double
00099 ydist(gdtpoint q) const;
00100
00101
00108 gdtpoint
00109 rotate(gdtpoint q, double a);
00110
00111 };
00112
00113
00114
00115
00116 std::ostream& operator<< (std::ostream& os, const gdtpoint& p);
00117
00118 std::istream& operator>> (std::istream& is, gdtpoint& p);
00119
00120 bool operator!=(const gdt::gdtpoint& p1, const gdt::gdtpoint& p2);
00121
00122 bool operator==(const gdt::gdtpoint& p1, const gdt::gdtpoint& p2);
00123
00126 class gdtsegment {
00127
00128 private:
00129 gdtpoint point1;
00130 gdtpoint point2;
00131
00132 public:
00133
00134 gdtsegment();
00135
00136 ~gdtsegment();
00137
00138 gdtsegment(gdtpoint p1, gdtpoint p2);
00139
00140 gdtpoint start() const;
00141
00142 gdtpoint end() const;
00143
00144 bool is_horizontal();
00145
00146 bool is_vertical();
00147
00148 double length();
00149
00153 bool contains(gdtpoint p);
00154
00155
00161 bool intersection(gdtsegment b, gdtpoint& p);
00162
00163
00167 double direction();
00168
00169
00173 double angle();
00174
00178 double
00179 angle(gdtsegment t);
00180
00181
00182
00183
00184 double distance(gdtpoint p);
00185
00186 };
00187
00188
00189
00190 class gdtline {
00191
00192 private:
00193
00194
00195 double a;
00196 double b;
00197 double c;
00198
00199 double angle;
00200
00201 public:
00202
00203 gdtline(gdtpoint p1, gdtpoint p2);
00204
00205 ~gdtline();
00206
00207 double direction() const;
00208
00209 };
00210
00211 std::ostream& operator<< (std::ostream& os, const gdtsegment& s);
00212
00213
00214 class gdtpolygon {
00215
00216 private:
00217 gdtlist<gdtpoint> polygon_vertices;
00218
00219 public:
00220
00221 gdtpolygon();
00222
00223 gdtpolygon(gdtlist<gdtpoint> V);
00224
00225 ~gdtpolygon();
00226
00227 gdtlist<gdtpoint>
00228 vertices() const;
00229
00230 gdtlist<gdtsegment> edges();
00231
00235 gdtlist<gdtpoint> intersection(gdtsegment s) ;
00236
00237 double perimeter();
00238
00239 double area();
00240
00241 };
00242
00243
00244
00245 class gdtcircle {
00246
00247 private:
00248 gdtpoint center;
00249 double radius;
00250
00251 public:
00252 gdtcircle(gdtpoint c, double r);
00253
00254 ~gdtcircle();
00255
00256 gdtlist<gdtpoint> intersection(gdtsegment s);
00257 };
00258
00259
00260 };
00261
00262
00263 #endif