BWAPI
|
00001 /***************************************************************** 00002 * File: point2d.h 00003 * Synopsis: 00004 * Basic 2-dimensional geometry 00005 * Author: Shubin Zhao (shubinz@cs.nyu.edu), 2001. 00006 * 00007 ***************************************************************** 00008 * CORE Library Version 1.4 (July 2001) 00009 * Chee Yap <yap@cs.nyu.edu> 00010 * Chen Li <chenli@cs.nyu.edu> 00011 * Zilin Du <zilin@cs.nyu.edu> 00012 * 00013 * Copyright (c) 1995, 1996, 1998, 1999, 2000, 2001 Exact Computation Project 00014 * 00015 * WWW URL: http://cs.nyu.edu/exact/ 00016 * Email: exact@cs.nyu.edu 00017 * 00018 * $Id: point2d.h 37060 2007-03-13 18:10:39Z reichel $ 00019 *****************************************************************/ 00020 00021 00022 #ifndef _POINT2D_H 00023 #define _POINT2D_H 00024 00025 #ifndef CORE_LEVEL 00026 # define CORE_LEVEL 3 00027 #endif 00028 00029 #include <CGAL/CORE/CORE.h> 00030 #include <CGAL/CORE/linearAlgebra.h> 00031 #include <CGAL/CORE/geombase.h> 00032 00033 class Point2d : public GeomObj { 00034 00035 private: 00036 double x, y; 00037 00038 public: 00039 00040 //CONSTRUCTORS 00041 // 00042 Point2d(); //initialized to origin(0,0) 00043 Point2d(double, double); 00044 Point2d(const Point2d &); 00045 Point2d(Vector v); 00046 //create a point initialized to the point $(v[0], v[1])$ 00047 //precondition: v.dim() = 2 00048 00049 //DESTRUCTOR 00050 virtual ~Point2d() {} 00051 00052 //ASSIGNMENT AND QUERY 00053 // 00054 Point2d& operator=(const Point2d&); 00055 00056 double X() const { return x; } 00057 double Y() const { return y; } 00058 void setX( const double a){ x = a; } 00059 void setY( const double a){ y = a; } 00060 void set( const double a, const double b){ x = a; y = b;} 00061 00062 int dim() const { return 2; } 00063 00064 //CONVERSION 00065 // 00066 Vector toVector() const { return Vector(X(), Y()); } 00067 00068 //DISTANCES 00069 // 00070 double distance(const Point2d) const; 00071 // returns the Euclidean distance between p and this 00072 00073 double distance() const { return distance(Point2d(0, 0)); } 00074 // returns distance between this and origin 00075 00076 //VECTOR OPERATIONS 00077 // 00078 Vector operator-(const Point2d &) const; 00079 Point2d operator+(const Vector &) const; 00080 00081 //TRANSFORMATIONS 00082 // 00083 Point2d rotate90( const Point2d& q); 00084 // returns the point rotated about q by angle of 90 degrees 00085 00086 //COMPARISONS 00087 // 00088 bool operator==(const Point2d&) const; 00089 bool operator!=(const Point2d& p) const {return !operator==(p); } 00090 00091 //INPUT-OUTPUT 00092 // 00093 friend std::ostream& operator<< (std::ostream&, const Point2d); 00094 // write point p to output stream 00095 // The format is, e.g., Point2d(1.0, 23) 00096 00097 friend std::istream& operator>> (std::istream&, Point2d&); 00098 // reads the x and y coordinates of point p from the input stream 00099 // The format is " ( x , y ) " where the white spaces are optional. 00100 // Even the comma and the "(" and ")" are optional. 00101 // The comment char '#' is allowed, and the rest of 00102 // the line is then treated as white space. 00103 // However, you must not use other kinds of parenthesis 00104 // E.g., the following are all equivalent: 00105 // 1.0 -0.2 # comment 00106 // ( +1.0, -0.2) 00107 // 1.0, -.2 00108 00109 friend int readPoints(std::istream &iS, 00110 Point2d *pA, int MaxN = 1000, int N = 0); 00111 // reads a sequence of points from input stream iS into Point2d array pA. 00112 // The input stream constains a sequence of 2K+1 numbers of the form 00113 // [NN] ( x1 , y1 ) ( x2 , y2 ) ... ( xK , yK ) 00114 // The i-th point is (xi, yi). 00115 // (0) NN is optional if N is given as argument (then N is set to NN) 00116 // (1) Any of the "(", "," and ")" are optional 00117 // (2) Newlines, extra white spaces, '#' are all ignored. 00118 // (3) Also, everything after '#' is discarded. 00119 // If N > MaxN, nothing is read and 0 is returned. 00120 // Returns the number of points actually read, i.e, min(K, N). 00121 00122 }; //Point2d Class 00123 00124 // ////////////////////////////////////////////////// 00125 // AUXILLIARY FUNCTIONS: 00126 // ////////////////////////////////////////////////// 00127 00128 Point2d midPoint(const Point2d& a, const Point2d& b); 00129 // returns midpoint between a and b 00130 00131 Point2d aCenter(const Point2d& a, const Point2d& b, machine_double alpha =0.5); 00132 // returns the "asymmetric Center" point 00133 // that is alpha-fraction of the distance from a to b 00134 00135 double area(const Point2d& a, const Point2d& b, const Point2d& c); 00136 // returns twice (!) the signed area of triangle (a,b,c) 00137 00138 int orientation2d(const Point2d& a, const Point2d& b, const Point2d& c); 00139 // returns sign of area(a,b,c) 00140 00141 bool leftTurn(const Point2d& a, const Point2d& b, const Point2d& c); 00142 // returns true iff orientation2d(a,b,c) = +1 00143 00144 bool rightTurn(const Point2d& a, const Point2d& b, const Point2d& c); 00145 // returns true iff orientation2d(a,b,c) = -1 00146 00147 bool collinear(const Point2d& a, const Point2d& b, const Point2d& c); 00148 // returns true iff orientation2d(a,b,c) = 0 00149 00150 bool between(const Point2d& a, const Point2d& b, const Point2d& c); 00151 // returns true iff orientation2d(a,b,c) = 0 and b is strictly 00152 // between a and c. 00153 00154 //variant of between: 00155 bool betweenVar(const Point2d& a, const Point2d& b, const Point2d& c); 00156 // returns true iff the scalar product (a-b, c-b) is positive. 00157 // In case orientation2d(a,b,c)=0, then this is equivalent to 00158 // b being strictly between a and c. 00159 00160 // THE FOLLOWING ARE CALLED by 00161 // operator>>(..) and readPoints(..) 00162 // bool getToNum( std::istream& in, char mark, bool strict=false) ; 00163 // bool getToChar( std::istream& in, char mark) ; 00164 // bool startNum(char c) ; 00165 00166 #endif