Main Page Class Hierarchy Compound List File List Compound Members Related Pages

# 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     void normalize();
    00065     SCVector3 operator -() { return SCVector3(-_v[0],-_v[1],-_v[2]); }
    00066     SCVector3 operator*(double) const;
    00067     void operator = (const double *x) {
    00068         _v[0] = x[0];
    00069         _v[1] = x[1];
    00070         _v[2] = x[2];
    00071       }
    00072     void operator = (const SCVector3& x) {
    00073         _v[0] = x._v[0];
    00074         _v[1] = x._v[1];
    00075         _v[2] = x._v[2];
    00076       }
    00077     void operator = (double d) { _v[0] = d; _v[1] = d; _v[2] = d; }
    00078     void operator -= (const SCVector3& v) {
    00079         _v[0] -= v._v[0];
    00080         _v[1] -= v._v[1];
    00081         _v[2] -= v._v[2];
    00082       }
    00083     void operator += (const SCVector3& v) {
    00084         _v[0] += v._v[0];
    00085         _v[1] += v._v[1];
    00086         _v[2] += v._v[2];
    00087       }
    00088     void operator *= (double m) { _v[0] *= m; _v[1] *= m; _v[2] *= m; }
    00089     SCVector3 operator+(const SCVector3&v) const {
    00090         SCVector3 result;
    00091         result._v[0] = _v[0] + v._v[0];
    00092         result._v[1] = _v[1] + v._v[1];
    00093         result._v[2] = _v[2] + v._v[2];
    00094         return result;
    00095       }
    00096     SCVector3 operator-(const SCVector3&v) const {
    00097         SCVector3 result;
    00098         result._v[0] = _v[0] - v._v[0];
    00099         result._v[1] = _v[1] - v._v[1];
    00100         result._v[2] = _v[2] - v._v[2];
    00101         return result;
    00102       }
    00103     double dot(const SCVector3&v) const {
    00104         return _v[0]*v._v[0] + _v[1]*v._v[1] + _v[2]*v._v[2]; }
    00105     SCVector3 cross(const SCVector3&) const;
    00106     // returns a unit vector that is perpendicular to the two vectors
    00107     SCVector3 perp_unit(const SCVector3&) const;
    00108     void spherical_coord(double theta, double phi,
    00109                          double r);
    00110     void spherical_to_cartesian(SCVector3&cart) const;
    00111     double maxabs() const;
    00112     // this returns the length of the difference vector
    00113     double dist(const SCVector3&) const;
    00114     void rotate(double theta,SCVector3 &v);
    00115     double norm() const { return sqrt(this->dot(*this)); }
    00116     double& elem(int xyz) { return _v[xyz]; }
    00117     const double& elem(int xyz) const { return _v[xyz]; }
    00118     double& operator [] (int i) { return _v[i]; }
    00119     const double& operator [] (int i) const { return _v[i]; }
    00120     double& operator () (int i) { return _v[i]; }
    00121     const double& operator () (int i) const { return _v[i]; }
    00122     const double* data() const { return _v; }
    00123     double* data() { return _v; }
    00124     double& x() { return _v[0]; }
    00125     double& y() { return _v[1]; }
    00126     double& z() { return _v[2]; }
    00127     const double& x() const { return _v[0]; }
    00128     const double& y() const { return _v[1]; }
    00129     const double& z() const { return _v[2]; }
    00130     double& r() { return _v[0]; }
    00131     double& theta() { return _v[1]; }
    00132     double& phi() { return _v[2]; }
    00133     const double& r() const { return _v[0]; }
    00134     const double& theta() const { return _v[1]; }
    00135     const double& phi() const { return _v[2]; }
    00136     void print(std::ostream& =ExEnv::out0()) const;
    00137 };
    00138 SCVector3 operator*(double,const SCVector3&);
    00139 std::ostream &operator<<(std::ostream&, const SCVector3 &);
    00140
    00141 }
    00142
    00143 #ifdef INLINE_FUNCTIONS
    00144 #include <math/scmat/vector3_i.h>
    00145 #endif
    00146
    00147 #endif
    00148
    00149 // Local Variables:
    00150 // mode: c++
    00151 // c-file-style: "CLJ"
    00152 // End: