00001
00002
00003
00004
00005
00006
00007 #ifndef IMPALGEBRA_SPHERICAL_VECTOR_3D_H
00008 #define IMPALGEBRA_SPHERICAL_VECTOR_3D_H
00009
00010 #include "algebra_config.h"
00011 #include "Vector3D.h"
00012 #include "IMP/exception.h"
00013 #include "IMP/constants.h"
00014 #include <cmath>
00015
00016 IMPALGEBRA_BEGIN_NAMESPACE
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 class IMPALGEBRAEXPORT SphericalVector3D
00027 {
00028 bool check(double r, double theta, double psi);
00029 public:
00030 SphericalVector3D() {};
00031
00032
00033
00034 SphericalVector3D(VectorD<3> &v) {
00035 set_cartesian_coordinates(v);
00036 }
00037
00038
00039
00040
00041
00042
00043 SphericalVector3D(double r, double theta,
00044 double psi,bool apply_check=true) {
00045 if(apply_check) {
00046 if(!check(r,theta,psi)) {
00047 String msg = "SphericalCoords:: wrong SphericalCoords coordinates." ;
00048 throw ValueException(msg.c_str());
00049 }
00050 }
00051 v_[0] = r;
00052 v_[1] = theta;
00053 v_[2] = psi;
00054 }
00055
00056 double operator[](unsigned int i) const {
00057 IMP_USAGE_CHECK(i < 3, "Invalid component of SphericalCoords requested: "
00058 << i << " of " << 3);
00059 return v_[i];
00060 }
00061
00062 double& operator[](unsigned int i) {
00063 IMP_USAGE_CHECK(i < 3, "Invalid component of SphericalCoords requested: "
00064 << i << " of " << 3);
00065 return v_[i];
00066 }
00067
00068
00069 VectorD<3> get_cartesian_coordinates();
00070
00071 IMP_SHOWABLE_INLINE(out << v_[0] << " , " << v_[1] << " , "
00072 << v_[2]);
00073
00074 private:
00075 void set_cartesian_coordinates(VectorD<3>& v);
00076 double v_[3];
00077 };
00078
00079 IMP_OUTPUT_OPERATOR(SphericalVector3D);
00080
00081 IMP_VALUES(SphericalVector3D);
00082
00083 IMPALGEBRA_END_NAMESPACE
00084
00085 #endif