00001 #ifndef MSL_POINT_H 00002 #define MSL_POINT_H 00003 00004 #include <stream.h> 00005 #include <list.h> 00006 00007 class MSLPoint 00008 { 00009 double xrep; 00010 double yrep; 00011 00012 public: 00013 00014 MSLPoint(); 00015 MSLPoint(double x, double y); 00016 ~MSLPoint() {} 00017 double xcoord() const { return xrep; } 00018 double ycoord() const { return yrep; } 00019 void normalize() const {} 00020 int dim() const { return 2; } 00021 double sqr_dist(const MSLPoint& q) const; 00022 double xdist(const MSLPoint& q) const; 00023 double ydist(const MSLPoint& q) const; 00024 double distance(const MSLPoint& q) const; 00025 double distance() const { return distance(MSLPoint(0,0)); } 00026 double angle(const MSLPoint& q, const MSLPoint& r) const; 00027 MSLPoint translate_by_angle(double alpha, double d) const; 00028 MSLPoint translate(double dx, double dy) const; 00029 MSLPoint rotate(const MSLPoint& q, double a) const; 00030 MSLPoint rotate(double a) const; 00031 MSLPoint rotate90(const MSLPoint& q) const; 00032 MSLPoint rotate90() const; 00033 MSLPoint reflect(const MSLPoint& q, const MSLPoint& r) const; 00034 MSLPoint reflect(const MSLPoint& q) const; 00035 bool operator==(const MSLPoint& q) const; 00036 bool operator!=(const MSLPoint& q) const { return !operator==(q);} 00037 00038 friend ostream& operator<<(ostream& O, const MSLPoint& p) ; 00039 friend istream& operator>>(istream& I, MSLPoint& p) ; 00040 friend istream& operator>>(istream& is, list<MSLPoint> & vl); 00041 friend ostream& operator<<(ostream& os, const list<MSLPoint> & vl); 00042 friend istream& operator>>(istream& is, list<list<MSLPoint> > & vl); 00043 friend ostream& operator<<(ostream& os, const list<list<MSLPoint> > & vl); 00044 }; 00045 00046 00047 inline MSLPoint center(const MSLPoint& a, const MSLPoint& b) { 00048 return MSLPoint((a.xcoord()+b.xcoord())/2,(a.ycoord()+b.ycoord())/2); 00049 } 00050 00051 00052 inline MSLPoint midMSLPoint(const MSLPoint& a, const MSLPoint& b) { 00053 return center(a,b); 00054 } 00055 00056 00057 inline int orientation(const MSLPoint& a, const MSLPoint& b, const MSLPoint& c) 00058 { double d1 = (a.xcoord() - b.xcoord()) * (a.ycoord() - c.ycoord()); 00059 double d2 = (a.ycoord() - b.ycoord()) * (a.xcoord() - c.xcoord()); 00060 if (d1 == d2) return 0; else return (d1 > d2) ? +1 : -1; 00061 } 00062 00063 inline int cmp_signed_dist(const MSLPoint& a, const MSLPoint& b, 00064 const MSLPoint& c, const MSLPoint& d) 00065 { double d1 = (a.xcoord() - b.xcoord()) * (d.ycoord() - c.ycoord()); 00066 double d2 = (a.ycoord() - b.ycoord()) * (d.xcoord() - c.xcoord()); 00067 if (d1 == d2) return 0; else return (d1 > d2) ? +1 : -1; 00068 } 00069 00070 inline double area(const MSLPoint& a, const MSLPoint& b, const MSLPoint& c) 00071 { return ((a.xcoord()-b.xcoord()) * (a.ycoord()-c.ycoord()) - 00072 (a.ycoord()-b.ycoord()) * (a.xcoord()-c.xcoord()))/2; } 00073 00074 inline bool collinear(const MSLPoint& a, const MSLPoint& b, const MSLPoint& c) 00075 { return (a.ycoord()-b.ycoord()) * (a.xcoord()-c.xcoord()) == 00076 (a.xcoord()-b.xcoord()) * (a.ycoord()-c.ycoord()); } 00077 00078 inline bool right_turn(const MSLPoint& a, const MSLPoint& b, const MSLPoint& c) 00079 { return (a.xcoord()-b.xcoord()) * (a.ycoord()-c.ycoord()) < 00080 (a.ycoord()-b.ycoord()) * (a.xcoord()-c.xcoord()); } 00081 00082 inline bool left_turn(const MSLPoint& a, const MSLPoint& b, const MSLPoint& c) 00083 { return (a.xcoord()-b.xcoord()) * (a.ycoord()-c.ycoord()) > 00084 (a.ycoord()-b.ycoord()) * (a.xcoord()-c.xcoord()); } 00085 00086 extern int side_of_circle(const MSLPoint& a, const MSLPoint& b, 00087 const MSLPoint& c, const MSLPoint& d); 00088 00089 inline bool incircle(const MSLPoint& a, const MSLPoint& b, const MSLPoint& c, 00090 const MSLPoint& d) 00091 { return (orientation(a,b,c) * side_of_circle(a,b,c,d)) > 0; } 00092 00093 inline bool outcircle(const MSLPoint& a, const MSLPoint& b, const MSLPoint& c, 00094 const MSLPoint& d) 00095 { return (orientation(a,b,c) * side_of_circle(a,b,c,d)) < 0; } 00096 00097 inline bool cocircular(const MSLPoint& a, const MSLPoint& b, const MSLPoint& c, 00098 const MSLPoint& d) 00099 { return side_of_circle(a,b,c,d) == 0; } 00100 00101 00102 // Add a fake polygon class which is a list of points 00103 typedef list<MSLPoint> MSLPolygon; 00104 00105 #endif 00106