IMP  2.3.1
The Integrative Modeling Platform
SphericalVector3D.h
Go to the documentation of this file.
1 /**
2  * \file IMP/algebra/SphericalVector3D.h
3  * \brief Stores and converts spherical coordinates
4  *
5  * Copyright 2007-2014 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPALGEBRA_SPHERICAL_VECTOR_3D_H
9 #define IMPALGEBRA_SPHERICAL_VECTOR_3D_H
10 
11 #include <IMP/algebra/algebra_config.h>
12 #include "Vector3D.h"
13 #include "IMP/base/exception.h"
14 #include "constants.h"
16 #include "GeometricPrimitiveD.h"
17 #include <cmath>
18 
19 IMPALGEBRA_BEGIN_NAMESPACE
20 
21 //! Class to represent a 3D point in spherical coordinates
22 /**
23  The order assumed for the representation is radial distance, zenith,
24  and azimuth (r, theta, psi).
25  zenith - angle with axis z
26  azimuth - angle with axis x
27  \geometry
28 */
29 class IMPALGEBRAEXPORT SphericalVector3D : public GeometricPrimitiveD<3> {
30  bool check(double r, double theta, double psi);
31 
32  public:
33  SphericalVector3D() {};
34 
35  //! Constructor that directly converts to spherical coordinates from a vector
36  //! v in Cartesian coordinates
37  SphericalVector3D(const Vector3D& v) { set_cartesian_coordinates(v); }
38 
39  //! Direct Constructor. A check for the validity of the coords is done
40  //! by default
41  /**
42  Set apply_check to false if you do not want the check
43  **/
44  SphericalVector3D(double r, double theta, double psi,
45  bool apply_check = true) {
46  if (apply_check) {
47  if (!check(r, theta, psi)) {
48  String msg = "SphericalCoords:: wrong SphericalCoords coordinates.";
49  throw base::ValueException(msg.c_str());
50  }
51  }
52  v_[0] = r;
53  v_[1] = theta;
54  v_[2] = psi;
55  }
56 
57  double operator[](unsigned int i) const {
58  IMP_USAGE_CHECK(i < 3, "Invalid component of SphericalCoords requested: "
59  << i << " of " << 3);
60  return v_[i];
61  }
62 
63  double& operator[](unsigned int i) {
64  IMP_USAGE_CHECK(i < 3, "Invalid component of SphericalCoords requested: "
65  << i << " of " << 3);
66  return v_[i];
67  }
68 
69  //! Returns a vector with the Cartesian coordinates
70  Vector3D get_cartesian_coordinates();
71 
72  IMP_SHOWABLE_INLINE(SphericalVector3D, out << v_[0] << " , " << v_[1] << " , "
73  << v_[2]);
74 
75  private:
76  void set_cartesian_coordinates(const Vector3D& v);
77  double v_[3];
78 };
79 
81 
82 IMPALGEBRA_END_NAMESPACE
83 
84 #endif /* IMPALGEBRA_SPHERICAL_VECTOR_3D_H */
Basic types used by IMP.
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
Exception definitions and assertions.
SphericalVector3D(const Vector3D &v)
#define IMP_VALUES(Name, PluralName)
Define the type for storing sets of values.
Definition: value_macros.h:23
Base class for geometric types.
SphericalVector3D(double r, double theta, double psi, bool apply_check=true)
Various useful constants.
Class to represent a 3D point in spherical coordinates.
VectorD< 3 > Vector3D
Definition: VectorD.h:395
Simple 3D vector class.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Definition: check_macros.h:170
std::string String
Basic string value.
Definition: types.h:44
Various general useful macros for IMP.
An exception for an invalid value being passed to IMP.
Definition: exception.h:137