dpoint3.h

Go to the documentation of this file.
00001 /**********************************************************************
00002  *<
00003     FILE: dpoint3.h
00004 
00005     DESCRIPTION:
00006 
00007     CREATED BY: Dan Silva
00008 
00009     HISTORY:
00010 
00011  *> Copyright (c) 1994, All Rights Reserved.
00012  **********************************************************************/
00013 
00014 #pragma once
00015 
00016 #include "GeomExport.h"
00017 #include "maxheap.h"
00018 #include "point3.h"
00019 #include <iosfwd>
00020 
00029 class DPoint3: public MaxHeapOperators {
00030 public:
00031     double x,y,z;
00032 
00033     // Constructors
00035     DPoint3(){}
00038     DPoint3(double X, double Y, double Z)  { x = X; y = Y; z = Z;  }
00041     DPoint3(const DPoint3& a) { x = a.x; y = a.y; z = a.z; } 
00042     DPoint3(const Point3& a) { x = a.x; y = a.y; z = a.z; } 
00047     DPoint3(double af[3]) { x = af[0]; y = af[1]; z = af[2]; }
00048 
00049     // Access operators
00052     double& operator[](int i) { return (&x)[i]; }
00055     const double& operator[](int i) const { return (&x)[i]; }  
00056 
00057     // Conversion function
00059     operator double*() { return(&x); }
00060 
00061     // Unary operators
00063     DPoint3 operator-() const { return(DPoint3(-x,-y,-z)); } 
00065     DPoint3 operator+() const { return *this; } 
00066 
00067     // Assignment operators
00068     GEOMEXPORT DPoint3& operator=(const Point3& a) {    x = a.x; y = a.y; z = a.z;  return *this; }
00070     GEOMEXPORT DPoint3& operator-=(const DPoint3&);
00072     GEOMEXPORT DPoint3& operator+=(const DPoint3&);
00075     GEOMEXPORT DPoint3& operator*=(double);
00078     GEOMEXPORT DPoint3& operator/=(double);
00079 
00080     // Binary operators
00082     GEOMEXPORT DPoint3 operator-(const DPoint3&) const;
00084     GEOMEXPORT DPoint3 operator+(const DPoint3&) const;
00087     GEOMEXPORT double operator*(const DPoint3&) const;      // DOT PRODUCT
00090     GEOMEXPORT DPoint3 operator^(const DPoint3&) const; // CROSS PRODUCT
00091 
00092     };
00093 
00096 GEOMEXPORT double Length(const DPoint3&); 
00099 GEOMEXPORT int MaxComponent(const DPoint3&);  // the component with the maximum abs value
00102 GEOMEXPORT int MinComponent(const DPoint3&);  // the component with the minimum abs value
00105 GEOMEXPORT DPoint3 Normalize(const DPoint3&); // Return a unit vector.
00106 
00107 GEOMEXPORT DPoint3 operator*(double, const DPoint3&);   // multiply by scalar
00108 GEOMEXPORT DPoint3 operator*(const DPoint3&, double);   // multiply by scalar
00109 GEOMEXPORT DPoint3 operator/(const DPoint3&, double);   // divide by scalar
00110 
00111 
00112 GEOMEXPORT std::ostream &operator<<(std::ostream&, const DPoint3&); 
00113      
00114 // Inlines:
00115 
00116 inline double Length(const DPoint3& v) {    
00117     return (double)sqrt(v.x*v.x+v.y*v.y+v.z*v.z);
00118     }
00119 
00120 inline DPoint3& DPoint3::operator-=(const DPoint3& a) { 
00121     x -= a.x;   y -= a.y;   z -= a.z;
00122     return *this;
00123     }
00124 
00125 inline DPoint3& DPoint3::operator+=(const DPoint3& a) {
00126     x += a.x;   y += a.y;   z += a.z;
00127     return *this;
00128     }
00129 
00130 inline DPoint3& DPoint3::operator*=(double f) {
00131     x *= f;   y *= f;   z *= f;
00132     return *this;
00133     }
00134 
00135 inline DPoint3& DPoint3::operator/=(double f) { 
00136     x /= f; y /= f; z /= f; 
00137     return *this; 
00138     }
00139 
00140 inline DPoint3 DPoint3::operator-(const DPoint3& b) const {
00141     return(DPoint3(x-b.x,y-b.y,z-b.z));
00142     }
00143 
00144 inline DPoint3 DPoint3::operator+(const DPoint3& b) const {
00145     return(DPoint3(x+b.x,y+b.y,z+b.z));
00146     }
00147 
00148 inline double DPoint3::operator*(const DPoint3& b) const {  
00149     return(x*b.x+y*b.y+z*b.z);  
00150     }
00151 
00152 inline DPoint3 operator*(double f, const DPoint3& a) {
00153     return(DPoint3(a.x*f, a.y*f, a.z*f));
00154     }
00155 
00156 inline DPoint3 operator*(const DPoint3& a, double f) {
00157     return(DPoint3(a.x*f, a.y*f, a.z*f));
00158     }
00159 
00160 inline DPoint3 operator/(const DPoint3& a, double f) {
00161     return(DPoint3(a.x/f, a.y/f, a.z/f));
00162     }
00163 
00165 GEOMEXPORT DPoint3 CrossProd(const DPoint3& a, const DPoint3& b);   // CROSS PRODUCT
00166     
00168 GEOMEXPORT double DotProd(const DPoint3& a, const DPoint3& b) ;     // DOT PRODUCT
00169 
00170