vector3.h

00001 //
00002 // vector3.h
00003 //
00004 // Copyright (C) 1996 Limit Point Systems, Inc.
00005 //
00006 // Author: Curtis Janssen <cljanss@limitpt.com>
00007 // Maintainer: LPS
00008 //
00009 // This file is part of the SC Toolkit.
00010 //
00011 // The SC Toolkit is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Library General Public License as published by
00013 // the Free Software Foundation; either version 2, or (at your option)
00014 // any later version.
00015 //
00016 // The SC Toolkit is distributed in the hope that it will be useful,
00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 // GNU Library General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Library General Public License
00022 // along with the SC Toolkit; see the file COPYING.LIB.  If not, write to
00023 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
00024 //
00025 // The U.S. Government is granted a limited license as per AL 91-7.
00026 //
00027 
00028 #ifndef _math_scmat_vector3_h
00029 #define _math_scmat_vector3_h
00030 #ifdef __GNUC__
00031 #pragma interface
00032 #endif
00033 
00034 #include <iostream>
00035 #include <math.h>
00036 
00037 #include <util/misc/exenv.h>
00038 #include <util/keyval/keyval.h>
00039 
00040 namespace sc {
00041 
00042 class RefSCVector;
00043 class SCMatrix3;
00044 
00045 class SCVector3
00046 {
00047     friend class SCMatrix3;
00048   private:
00049     double _v[3];
00050   public:
00051     SCVector3() {}
00052     SCVector3(const double p[3]) {
00053         _v[0] = p[0]; _v[1] = p[1]; _v[2] = p[2];
00054       }
00055     SCVector3(double d) { _v[0] = d; _v[1] = d; _v[2] = d; }
00056     SCVector3(double x,double y,double z) {
00057         _v[0] = x; _v[1] = y; _v[2] = z;
00058       }
00059     SCVector3(const SCVector3&p) {
00060         _v[0] = p._v[0]; _v[1] = p._v[1]; _v[2] = p._v[2];
00061       }
00062     SCVector3(const RefSCVector&);
00063     SCVector3(const Ref<KeyVal>&);
00064     ~SCVector3() {}
00065     void normalize();
00066     SCVector3 operator -() { return SCVector3(-_v[0],-_v[1],-_v[2]); }
00067     SCVector3 operator*(double) const;
00068     void operator = (const double *x) {
00069         _v[0] = x[0];
00070         _v[1] = x[1];
00071         _v[2] = x[2];
00072       }
00073     void operator = (const SCVector3& x) {
00074         _v[0] = x._v[0];
00075         _v[1] = x._v[1];
00076         _v[2] = x._v[2];
00077       }
00078     void operator = (double d) { _v[0] = d; _v[1] = d; _v[2] = d; }
00079     void operator -= (const SCVector3& v) {
00080         _v[0] -= v._v[0];
00081         _v[1] -= v._v[1];
00082         _v[2] -= v._v[2];
00083       }
00084     void operator += (const SCVector3& v) {
00085         _v[0] += v._v[0];
00086         _v[1] += v._v[1];
00087         _v[2] += v._v[2];
00088       }
00089     void operator *= (double m) { _v[0] *= m; _v[1] *= m; _v[2] *= m; }
00090     SCVector3 operator+(const SCVector3&v) const {
00091         SCVector3 result;
00092         result._v[0] = _v[0] + v._v[0];
00093         result._v[1] = _v[1] + v._v[1];
00094         result._v[2] = _v[2] + v._v[2];
00095         return result;
00096       }
00097     SCVector3 operator-(const SCVector3&v) const {
00098         SCVector3 result;
00099         result._v[0] = _v[0] - v._v[0];
00100         result._v[1] = _v[1] - v._v[1];
00101         result._v[2] = _v[2] - v._v[2];
00102         return result;
00103       }
00104     double dot(const SCVector3&v) const {
00105         return _v[0]*v._v[0] + _v[1]*v._v[1] + _v[2]*v._v[2]; }
00106     SCVector3 cross(const SCVector3&) const;
00107     // returns a unit vector that is perpendicular to the two vectors
00108     SCVector3 perp_unit(const SCVector3&) const;
00109     void spherical_coord(double theta, double phi, 
00110                          double r);
00111     void spherical_to_cartesian(SCVector3&cart) const;
00112     double maxabs() const;
00113     // this returns the length of the difference vector
00114     double dist(const SCVector3&) const;
00115     void rotate(double theta,SCVector3 &v);
00116     double norm() const { return sqrt(this->dot(*this)); }
00117     double& elem(int xyz) { return _v[xyz]; }
00118     const double& elem(int xyz) const { return _v[xyz]; }
00119     double& operator [] (int i) { return _v[i]; }
00120     const double& operator [] (int i) const { return _v[i]; }
00121     double& operator () (int i) { return _v[i]; }
00122     const double& operator () (int i) const { return _v[i]; }
00123     const double* data() const { return _v; }
00124     double* data() { return _v; }
00125     double& x() { return _v[0]; }
00126     double& y() { return _v[1]; }
00127     double& z() { return _v[2]; }
00128     const double& x() const { return _v[0]; }
00129     const double& y() const { return _v[1]; }
00130     const double& z() const { return _v[2]; }
00131     double& r() { return _v[0]; }
00132     double& theta() { return _v[1]; }
00133     double& phi() { return _v[2]; }
00134     const double& r() const { return _v[0]; }
00135     const double& theta() const { return _v[1]; }
00136     const double& phi() const { return _v[2]; }
00137     void print(std::ostream& =ExEnv::out0()) const;
00138 };
00139 SCVector3 operator*(double,const SCVector3&);
00140 std::ostream &operator<<(std::ostream&, const SCVector3 &);
00141 
00142 }
00143 
00144 #ifdef INLINE_FUNCTIONS
00145 #include <math/scmat/vector3_i.h>
00146 #endif
00147 
00148 #endif
00149 
00150 // Local Variables:
00151 // mode: c++
00152 // c-file-style: "CLJ"
00153 // End:

Generated at Wed Sep 5 14:02:31 2007 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.5.2.
These pages are hosted on SourceForge.net