00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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 class RefSCVector;
00041 class SCMatrix3;
00042
00043 class SCVector3
00044 {
00045 friend class SCMatrix3;
00046 private:
00047 double _v[3];
00048 public:
00049 SCVector3() {}
00050 SCVector3(const double p[3]) {
00051 _v[0] = p[0]; _v[1] = p[1]; _v[2] = p[2];
00052 }
00053 SCVector3(double d) { _v[0] = d; _v[1] = d; _v[2] = d; }
00054 SCVector3(double x,double y,double z) {
00055 _v[0] = x; _v[1] = y; _v[2] = z;
00056 }
00057 SCVector3(const SCVector3&p) {
00058 _v[0] = p._v[0]; _v[1] = p._v[1]; _v[2] = p._v[2];
00059 }
00060 SCVector3(const RefSCVector&);
00061 SCVector3(const Ref<KeyVal>&);
00062 void normalize();
00063 SCVector3 operator -() { return SCVector3(-_v[0],-_v[1],-_v[2]); }
00064 SCVector3 operator*(double) const;
00065 void operator = (const double *x) {
00066 _v[0] = x[0];
00067 _v[1] = x[1];
00068 _v[2] = x[2];
00069 }
00070 void operator = (const SCVector3& x) {
00071 _v[0] = x._v[0];
00072 _v[1] = x._v[1];
00073 _v[2] = x._v[2];
00074 }
00075 void operator = (double d) { _v[0] = d; _v[1] = d; _v[2] = d; }
00076 void operator -= (const SCVector3& v) {
00077 _v[0] -= v._v[0];
00078 _v[1] -= v._v[1];
00079 _v[2] -= v._v[2];
00080 }
00081 void operator += (const SCVector3& v) {
00082 _v[0] += v._v[0];
00083 _v[1] += v._v[1];
00084 _v[2] += v._v[2];
00085 }
00086 void operator *= (double m) { _v[0] *= m; _v[1] *= m; _v[2] *= m; }
00087 SCVector3 operator+(const SCVector3&v) const {
00088 SCVector3 result;
00089 result._v[0] = _v[0] + v._v[0];
00090 result._v[1] = _v[1] + v._v[1];
00091 result._v[2] = _v[2] + v._v[2];
00092 return result;
00093 }
00094 SCVector3 operator-(const SCVector3&v) const {
00095 SCVector3 result;
00096 result._v[0] = _v[0] - v._v[0];
00097 result._v[1] = _v[1] - v._v[1];
00098 result._v[2] = _v[2] - v._v[2];
00099 return result;
00100 }
00101 double dot(const SCVector3&v) const {
00102 return _v[0]*v._v[0] + _v[1]*v._v[1] + _v[2]*v._v[2]; }
00103 SCVector3 cross(const SCVector3&) const;
00104
00105 SCVector3 perp_unit(const SCVector3&) const;
00106 void spherical_coord(double theta, double phi,
00107 double r);
00108 void spherical_to_cartesian(SCVector3&cart) const;
00109 double maxabs() const;
00110
00111 double dist(const SCVector3&) const;
00112 void rotate(double theta,SCVector3 &v);
00113 double norm() const { return sqrt(this->dot(*this)); }
00114 double& elem(int xyz) { return _v[xyz]; }
00115 const double& elem(int xyz) const { return _v[xyz]; }
00116 double& operator [] (int i) { return _v[i]; }
00117 const double& operator [] (int i) const { return _v[i]; }
00118 double& operator () (int i) { return _v[i]; }
00119 const double& operator () (int i) const { return _v[i]; }
00120 const double* data() const { return _v; }
00121 double* data() { return _v; }
00122 double& x() { return _v[0]; }
00123 double& y() { return _v[1]; }
00124 double& z() { return _v[2]; }
00125 const double& x() const { return _v[0]; }
00126 const double& y() const { return _v[1]; }
00127 const double& z() const { return _v[2]; }
00128 double& r() { return _v[0]; }
00129 double& theta() { return _v[1]; }
00130 double& phi() { return _v[2]; }
00131 const double& r() const { return _v[0]; }
00132 const double& theta() const { return _v[1]; }
00133 const double& phi() const { return _v[2]; }
00134 void print(std::ostream& =ExEnv::out()) const;
00135 };
00136 SCVector3 operator*(double,const SCVector3&);
00137 std::ostream &operator<<(std::ostream&, const SCVector3 &);
00138
00139 #ifdef INLINE_FUNCTIONS
00140 #include <math/scmat/vector3_i.h>
00141 #endif
00142
00143 #endif
00144
00145
00146
00147
00148