title
Graph Drawing Toolkit

An object-oriented C++ library for handling and drawing graphs

gdtgeometry.h

Go to the documentation of this file.
00001 /*******************************************************************************
00002 +
00003 +  gdtpoint.h
00004 +
00005 +  This file is part of GDToolkit. It can be
00006 +  used free of charge in academic research and teaching.
00007 +  Any direct or indirect commercial use of this software is illegal
00008 +  without a written authorization of
00009 +  the Dipartimento di Informatica e Automazione
00010 +  Universita' di Roma Tre, Roma, ITALIA
00011 +
00012 +
00013 *******************************************************************************/
00014 
00015 // Pier Francesco Cortese - Jan 2004
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 {  // 2-dimensional point
00039 
00040         private:
00041 
00042         double x_coord;
00043         double y_coord;
00044 
00045     public:
00046 
00047     // Constructors
00048 
00049         gdtpoint();
00050 
00051         gdtpoint(double x, double y);
00052 
00053         ~gdtpoint();
00054 
00055     //Access Operations
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 }; // end of class gdtpoint
00112 
00113 
00114 // gdtpoint non-member functions
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 {    // 2-dimensional segment
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 /*Returns the distance between this segment and point p
00183 */              
00184                 double distance(gdtpoint p);
00185 
00186 }; // end of class gdtsegment
00187 
00188 
00189 
00190 class gdtline {
00191 
00192         private:
00193 
00194         // line is ax+by+c=0
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 }; // end of class gdtline
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 };  // end of class gdtpolygon
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 }; // end of class gdtcircle
00258 
00259 
00260 };  // end of namespace gdt
00261 
00262 
00263 #endif

Generated on Thu Jan 10 14:48:01 2008 for GDToolkit GAPI by  doxygen 1.5.3