| [0b990d] | 1 | // | 
|---|
|  | 2 | // vector3.h | 
|---|
|  | 3 | // | 
|---|
|  | 4 | // Copyright (C) 1996 Limit Point Systems, Inc. | 
|---|
|  | 5 | // | 
|---|
|  | 6 | // Author: Curtis Janssen <cljanss@limitpt.com> | 
|---|
|  | 7 | // Maintainer: LPS | 
|---|
|  | 8 | // | 
|---|
|  | 9 | // This file is part of the SC Toolkit. | 
|---|
|  | 10 | // | 
|---|
|  | 11 | // The SC Toolkit is free software; you can redistribute it and/or modify | 
|---|
|  | 12 | // it under the terms of the GNU Library General Public License as published by | 
|---|
|  | 13 | // the Free Software Foundation; either version 2, or (at your option) | 
|---|
|  | 14 | // any later version. | 
|---|
|  | 15 | // | 
|---|
|  | 16 | // The SC Toolkit is distributed in the hope that it will be useful, | 
|---|
|  | 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
|  | 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
|  | 19 | // GNU Library General Public License for more details. | 
|---|
|  | 20 | // | 
|---|
|  | 21 | // You should have received a copy of the GNU Library General Public License | 
|---|
|  | 22 | // along with the SC Toolkit; see the file COPYING.LIB.  If not, write to | 
|---|
|  | 23 | // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | 
|---|
|  | 24 | // | 
|---|
|  | 25 | // The U.S. Government is granted a limited license as per AL 91-7. | 
|---|
|  | 26 | // | 
|---|
|  | 27 |  | 
|---|
|  | 28 | #ifndef _math_scmat_vector3_h | 
|---|
|  | 29 | #define _math_scmat_vector3_h | 
|---|
|  | 30 | #ifdef __GNUC__ | 
|---|
|  | 31 | #pragma interface | 
|---|
|  | 32 | #endif | 
|---|
|  | 33 |  | 
|---|
|  | 34 | #include <iostream> | 
|---|
|  | 35 | #include <math.h> | 
|---|
|  | 36 |  | 
|---|
|  | 37 | #include <util/misc/exenv.h> | 
|---|
|  | 38 | #include <util/keyval/keyval.h> | 
|---|
|  | 39 |  | 
|---|
|  | 40 | namespace sc { | 
|---|
|  | 41 |  | 
|---|
|  | 42 | class RefSCVector; | 
|---|
|  | 43 | class SCMatrix3; | 
|---|
|  | 44 |  | 
|---|
|  | 45 | class SCVector3 | 
|---|
|  | 46 | { | 
|---|
|  | 47 | friend class SCMatrix3; | 
|---|
|  | 48 | private: | 
|---|
|  | 49 | double _v[3]; | 
|---|
|  | 50 | public: | 
|---|
|  | 51 | SCVector3() {} | 
|---|
|  | 52 | SCVector3(const double p[3]) { | 
|---|
|  | 53 | _v[0] = p[0]; _v[1] = p[1]; _v[2] = p[2]; | 
|---|
|  | 54 | } | 
|---|
|  | 55 | SCVector3(double d) { _v[0] = d; _v[1] = d; _v[2] = d; } | 
|---|
|  | 56 | SCVector3(double x,double y,double z) { | 
|---|
|  | 57 | _v[0] = x; _v[1] = y; _v[2] = z; | 
|---|
|  | 58 | } | 
|---|
|  | 59 | SCVector3(const SCVector3&p) { | 
|---|
|  | 60 | _v[0] = p._v[0]; _v[1] = p._v[1]; _v[2] = p._v[2]; | 
|---|
|  | 61 | } | 
|---|
|  | 62 | SCVector3(const RefSCVector&); | 
|---|
|  | 63 | SCVector3(const Ref<KeyVal>&); | 
|---|
|  | 64 | void normalize(); | 
|---|
|  | 65 | SCVector3 operator -() { return SCVector3(-_v[0],-_v[1],-_v[2]); } | 
|---|
|  | 66 | SCVector3 operator*(double) const; | 
|---|
|  | 67 | void operator = (const double *x) { | 
|---|
|  | 68 | _v[0] = x[0]; | 
|---|
|  | 69 | _v[1] = x[1]; | 
|---|
|  | 70 | _v[2] = x[2]; | 
|---|
|  | 71 | } | 
|---|
|  | 72 | void operator = (const SCVector3& x) { | 
|---|
|  | 73 | _v[0] = x._v[0]; | 
|---|
|  | 74 | _v[1] = x._v[1]; | 
|---|
|  | 75 | _v[2] = x._v[2]; | 
|---|
|  | 76 | } | 
|---|
|  | 77 | void operator = (double d) { _v[0] = d; _v[1] = d; _v[2] = d; } | 
|---|
|  | 78 | void operator -= (const SCVector3& v) { | 
|---|
|  | 79 | _v[0] -= v._v[0]; | 
|---|
|  | 80 | _v[1] -= v._v[1]; | 
|---|
|  | 81 | _v[2] -= v._v[2]; | 
|---|
|  | 82 | } | 
|---|
|  | 83 | void operator += (const SCVector3& v) { | 
|---|
|  | 84 | _v[0] += v._v[0]; | 
|---|
|  | 85 | _v[1] += v._v[1]; | 
|---|
|  | 86 | _v[2] += v._v[2]; | 
|---|
|  | 87 | } | 
|---|
|  | 88 | void operator *= (double m) { _v[0] *= m; _v[1] *= m; _v[2] *= m; } | 
|---|
|  | 89 | SCVector3 operator+(const SCVector3&v) const { | 
|---|
|  | 90 | SCVector3 result; | 
|---|
|  | 91 | result._v[0] = _v[0] + v._v[0]; | 
|---|
|  | 92 | result._v[1] = _v[1] + v._v[1]; | 
|---|
|  | 93 | result._v[2] = _v[2] + v._v[2]; | 
|---|
|  | 94 | return result; | 
|---|
|  | 95 | } | 
|---|
|  | 96 | SCVector3 operator-(const SCVector3&v) const { | 
|---|
|  | 97 | SCVector3 result; | 
|---|
|  | 98 | result._v[0] = _v[0] - v._v[0]; | 
|---|
|  | 99 | result._v[1] = _v[1] - v._v[1]; | 
|---|
|  | 100 | result._v[2] = _v[2] - v._v[2]; | 
|---|
|  | 101 | return result; | 
|---|
|  | 102 | } | 
|---|
|  | 103 | double dot(const SCVector3&v) const { | 
|---|
|  | 104 | return _v[0]*v._v[0] + _v[1]*v._v[1] + _v[2]*v._v[2]; } | 
|---|
|  | 105 | SCVector3 cross(const SCVector3&) const; | 
|---|
|  | 106 | // returns a unit vector that is perpendicular to the two vectors | 
|---|
|  | 107 | SCVector3 perp_unit(const SCVector3&) const; | 
|---|
|  | 108 | void spherical_coord(double theta, double phi, | 
|---|
|  | 109 | double r); | 
|---|
|  | 110 | void spherical_to_cartesian(SCVector3&cart) const; | 
|---|
|  | 111 | double maxabs() const; | 
|---|
|  | 112 | // this returns the length of the difference vector | 
|---|
|  | 113 | double dist(const SCVector3&) const; | 
|---|
|  | 114 | void rotate(double theta,SCVector3 &v); | 
|---|
|  | 115 | double norm() const { return sqrt(this->dot(*this)); } | 
|---|
|  | 116 | double& elem(int xyz) { return _v[xyz]; } | 
|---|
|  | 117 | const double& elem(int xyz) const { return _v[xyz]; } | 
|---|
|  | 118 | double& operator [] (int i) { return _v[i]; } | 
|---|
|  | 119 | const double& operator [] (int i) const { return _v[i]; } | 
|---|
|  | 120 | double& operator () (int i) { return _v[i]; } | 
|---|
|  | 121 | const double& operator () (int i) const { return _v[i]; } | 
|---|
|  | 122 | const double* data() const { return _v; } | 
|---|
|  | 123 | double* data() { return _v; } | 
|---|
|  | 124 | double& x() { return _v[0]; } | 
|---|
|  | 125 | double& y() { return _v[1]; } | 
|---|
|  | 126 | double& z() { return _v[2]; } | 
|---|
|  | 127 | const double& x() const { return _v[0]; } | 
|---|
|  | 128 | const double& y() const { return _v[1]; } | 
|---|
|  | 129 | const double& z() const { return _v[2]; } | 
|---|
|  | 130 | double& r() { return _v[0]; } | 
|---|
|  | 131 | double& theta() { return _v[1]; } | 
|---|
|  | 132 | double& phi() { return _v[2]; } | 
|---|
|  | 133 | const double& r() const { return _v[0]; } | 
|---|
|  | 134 | const double& theta() const { return _v[1]; } | 
|---|
|  | 135 | const double& phi() const { return _v[2]; } | 
|---|
|  | 136 | void print(std::ostream& =ExEnv::out0()) const; | 
|---|
|  | 137 | }; | 
|---|
|  | 138 | SCVector3 operator*(double,const SCVector3&); | 
|---|
|  | 139 | std::ostream &operator<<(std::ostream&, const SCVector3 &); | 
|---|
|  | 140 |  | 
|---|
|  | 141 | } | 
|---|
|  | 142 |  | 
|---|
|  | 143 | #ifdef INLINE_FUNCTIONS | 
|---|
|  | 144 | #include <math/scmat/vector3_i.h> | 
|---|
|  | 145 | #endif | 
|---|
|  | 146 |  | 
|---|
|  | 147 | #endif | 
|---|
|  | 148 |  | 
|---|
|  | 149 | // Local Variables: | 
|---|
|  | 150 | // mode: c++ | 
|---|
|  | 151 | // c-file-style: "CLJ" | 
|---|
|  | 152 | // End: | 
|---|