point3d.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                           point3d.h  -  description
00003                              -------------------
00004     begin                : Tue Mar 15 2005
00005     copyright            : (C) 2005-2006 by Ben Swerts
00006     email                : bswerts@users.sourceforge.net
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00019 
00028 
00029 
00030 
00031 #ifndef POINT3D_H
00032 #define POINT3D_H
00033 
00035 #include <cmath>
00036 
00037 
00039 template<class T> class Point3D
00040 {
00041   public:
00042     Point3D();                          // default constructor
00043     Point3D(const T x, const T y, const T z);     // constructs a point with coordinates x, y, z
00044     Point3D(const Point3D& p);          // copy constructor
00045     ~Point3D();                         // destructor
00046 
00048     T x() const;                        // returns the x-value
00049     T y() const;                        // returns the y-value
00050     T z() const;                        // returns the z-value
00051     unsigned int id() const;            // returns the point's ID (used in IsoSurface and PlotMapBase)
00052     bool operator==(const Point3D<double>& p) const         
00054     {
00055       if(xCoord == p.xCoord && yCoord == p.yCoord && zCoord == p.zCoord)
00056         return true;
00057       return fabs(xCoord - p.xCoord) < TOLERANCE && fabs(yCoord - p.yCoord) < TOLERANCE && fabs(zCoord - p.zCoord) < TOLERANCE;
00058     }
00059     bool operator==(const Point3D<float>& p) const          
00061     {
00062       if(xCoord == p.xCoord && yCoord == p.yCoord && zCoord == p.zCoord)
00063         return true;
00064       return fabs(xCoord - p.xCoord) < TOLERANCE && fabs(yCoord - p.yCoord) < TOLERANCE && fabs(zCoord - p.zCoord) < TOLERANCE;
00065     }
00066     bool operator==(const Point3D<unsigned int>& p) const   
00068     {  
00069       return xCoord == p.xCoord && yCoord == p.yCoord && zCoord == p.zCoord;
00070     }
00071 
00073     void setValues(const T x, const T y, const T z);           // sets the soordinates (cartesian by default)
00074     void setCartesian(const T x, const T y, const T z);        // sets the cartesian coordinates directly
00075     void setPolar(const T theta, const T phi, const T r);      // sets the coordinates from polar coordinates
00076     void setID(const unsigned int id);  // sets the point's ID
00077     void add(const Point3D& p);         // adds the point p (maybe do the same for adding a Vector3D to it)
00078 
00080     static const T PI;                  
00081     static const T DEGTORAD;            
00082     static const T RADTODEG;            
00083     static const T TOLERANCE;           
00084 
00085   private:
00087     T xCoord, yCoord, zCoord;           
00088     unsigned int ID;                    
00089 
00090 };
00091 
00095 
00097 template <class T> Point3D<T>::Point3D()
00099 {
00100   setValues(0, 0, 0);
00101 }
00102 
00104 template <class T> Point3D<T>::Point3D(const T x, const T y, const T z)
00106 {
00107   setValues(x, y, z);
00108 }
00109 
00111 template <class T> Point3D<T>::Point3D(const Point3D& p)
00113 {
00114   xCoord = p.xCoord;
00115   yCoord = p.yCoord;
00116   zCoord = p.zCoord;
00117   ID = p.ID;
00118 }
00119 
00121 template <class T> Point3D<T>::~Point3D()
00123 {
00124 
00125 }
00126 
00128 template <class T> T Point3D<T>::x() const
00130 {
00131   return xCoord;
00132 }
00133 
00135 template <class T> T Point3D<T>::y() const
00137 {
00138   return yCoord;
00139 }
00140 
00142 template <class T> T Point3D<T>::z() const
00144 {
00145   return zCoord;
00146 }
00147 
00149 template <class T> unsigned int Point3D<T>::id() const
00151 {
00152   return ID;
00153 }
00154 
00156 template <class T> void Point3D<T>::setValues(const T x, const T y, const T z)
00158 {
00159   xCoord = x;
00160   yCoord = y;
00161   zCoord = z;
00162 }
00163 
00165 template <class T> void Point3D<T>::setCartesian(const T x, const T y, const T z)
00167 {
00168   setValues(x, y, z);
00169 }
00170 
00172 template <class T> void Point3D<T>::setPolar(const T theta, const T phi, const T r)
00175 {
00176   setValues(r*sin(theta*DEGTORAD)*cos(phi*DEGTORAD), r*sin(theta*DEGTORAD)*sin(phi*DEGTORAD), r*cos(theta*DEGTORAD));
00177 }
00178 
00180 template <class T> void Point3D<T>::setID(const unsigned int id)
00182 {
00183   ID = id;
00184 }
00185 
00187 template <class T> void Point3D<T>::add(const Point3D& p)
00189 {
00190   xCoord += p.xCoord;
00191   yCoord += p.yCoord;
00192   zCoord += p.zCoord;
00193 }
00194 
00195 #endif
00196 

Generated on Fri May 19 14:31:55 2006 for Brabosphere by  doxygen 1.4.6-NO