BWAPI
|
00001 00002 /***************************************************************** 00003 * File: point3d.h 00004 * Synopsis: 00005 * Basic 3-dimensional geometry 00006 * Author: Shubin Zhao (shubinz@cs.nyu.edu), 2001. 00007 * 00008 ***************************************************************** 00009 * CORE Library Version 1.4 (July 2001) 00010 * Chee Yap <yap@cs.nyu.edu> 00011 * Chen Li <chenli@cs.nyu.edu> 00012 * Zilin Du <zilin@cs.nyu.edu> 00013 * 00014 * Copyright (c) 1995, 1996, 1998, 1999, 2000, 2001 Exact Computation Project 00015 * 00016 * WWW URL: http://cs.nyu.edu/exact/ 00017 * Email: exact@cs.nyu.edu 00018 * 00019 * $Id: point3d.h 37060 2007-03-13 18:10:39Z reichel $ 00020 *****************************************************************/ 00021 00022 #ifndef _POINT3D_H 00023 #define _POINT3D_H 00024 00025 #include <CGAL/CORE/CORE.h> 00026 #include <CGAL/CORE/linearAlgebra.h> 00027 #include <CGAL/CORE/geombase.h> 00028 00029 // class defination for 3d points 00030 class Point3d : public GeomObj{ 00031 00032 private: 00033 double x, y, z; 00034 00035 public: 00036 00037 /************************************************************ 00038 * constructors and destructors 00039 ************************************************************/ 00040 Point3d(); //initialized to origin(0,0,0) 00041 Point3d(double x, double y, double z); 00042 Point3d(const Point3d & p); 00043 Point3d(const Vector& v); 00044 //create a point initialized to the point $(v[0], v[1], v[2])$ 00045 //precondition: v.dim() >= 3 (only the first 3 components are used) 00046 00047 //destructor 00048 virtual ~Point3d() {} 00049 00050 /************************************************************ 00051 * Methods 00052 ************************************************************/ 00053 Point3d& operator=(const Point3d&); 00054 00055 double X() const { return x; } 00056 double Y() const { return y; } 00057 double Z() const { return z; } 00058 00059 Vector toVector() const { return Vector(x, y, z); } 00060 00061 virtual int dim() const { return 0; } 00062 00063 double distance(const Point3d& p) const; 00064 // returns the Euclidean distance between p and this 00065 00066 double distance() const { return distance(Point3d(0, 0, 0)); } 00067 // returns distance between this and origin 00068 00069 Point3d negate() const { return Point3d(-x, -y, -z); } 00070 Vector operator-(const Point3d &p) const; 00071 Point3d operator+(const Vector &v) const; 00072 Point3d operator-(const Vector &v) const; 00073 Point3d operator*(const double& d) const; 00074 00075 /************************************************************ 00076 * predicates 00077 ************************************************************/ 00078 00079 bool operator==(const Point3d&) const; 00080 bool operator!=(const Point3d& p) const {return !operator==(p); } 00081 00082 /************************************************************ 00083 * I/O, debugging 00084 ************************************************************/ 00085 friend std::ostream& operator<< (std::ostream&, const Point3d&); 00086 // write point p to output stream 00087 00088 friend std::istream& operator>>(std::istream&, Point3d&); 00089 // reads the x and y coordinates of point p from the input stream 00090 00091 // routines to display point: 00092 void dump() const { 00093 std::cout << "(" << x <<", " << y << z << ")" ; // simply outputs "(x, y)" 00094 } 00095 00096 void dump(const char* s) const { 00097 std::cout << s << "(" << x <<", " << y << z << ")" ; // s is the prefix message 00098 } 00099 00100 void dump(const char* s, const char* ss) const { 00101 std::cout << s << "(" << x <<", " << y << z << ss ; // ss is the suffix message 00102 } 00103 00104 // compute signed volume of a tetrahedron 00105 friend double signed_volume(const Point3d& a, const Point3d& b, 00106 const Point3d& c, const Point3d& d); 00107 00108 };//class Point3d 00109 00110 00111 /************************************************************ 00112 * Inline implementation and some 3d predicates 00113 ************************************************************/ 00114 // removed inline implementation for compile under visual c++ 00115 // Zilin Du 00116 00117 // midPt(p, q) returns (p+q)/2: 00118 Point3d midPt3d ( Point3d& a, Point3d& b); 00119 00120 /* orientation3d(a, b, c, d) 00121 * computes the orientation of points a, b, c, d as the sign 00122 * of the determinant 00123 * | ax ay az 1 | 00124 * | bx by bz 1 | 00125 * | cx cy cz 1 | 00126 * | dx dy dz 1 | 00127 * i.e., it returns +1 if d lies in the opposite side w.r.t. the 00128 * counter-clockwise side of plane formed by a, b, c 00129 */ 00130 int orientation3d(const Point3d& a, const Point3d& b, 00131 const Point3d& c, const Point3d& d); 00132 00133 /* area(a, b, c) returns 1/2 times the determinant of orientation(a,b,c) 00134 * above. This is the signed area of the triangle determined by a, b, c, 00135 * positive if orientation(a,b,c) > 0, and negative otherwise. */ 00136 00137 double volume(const Point3d& a, const Point3d& b, 00138 const Point3d& c, const Point3d& d); 00139 00140 00141 /* returns true if points a, b, c and d are coplanar, i.e., 00142 * orientation(a, b, c, d) = 0, and false otherwise. 00143 */ 00144 bool coplanar(const Point3d& a, const Point3d& b, 00145 const Point3d& c, const Point3d& d); 00146 00147 /************************************************************ 00148 * CONSTANTS 00149 ************************************************************/ 00150 00151 static Point3d ORIGIN_3D(0.0, 0.0, 0.0); 00152 static Point3d X_UNIT_3D(1.0, 0.0, 0.0); 00153 static Point3d Y_UNIT_3D(0.0, 1.0, 0.0); 00154 static Point3d Z_UNIT_3D(0.0, 0.0, 1.0); 00155 00156 #endif