IMP logo
IMP Reference Guide  2.13.0
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-2020 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/exception.h"
14 #include "constants.h"
15 #include <IMP/showable_macros.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) const;
31 
32  public:
33  SphericalVector3D() {};
34 
35  //! Construct from a Cartesian coordinate vector
36  SphericalVector3D(const Vector3D& v) { set_cartesian_coordinates(v); }
37 
38  //! Construct from provided spherical coordinates.
39  /** A check for the validity of the coords is done by default.
40  Set apply_check to false if you do not want the check.
41  */
42  SphericalVector3D(double r, double theta, double psi,
43  bool apply_check = true) {
44  if (apply_check) {
45  if (!check(r, theta, psi)) {
46  String msg = "SphericalCoords:: wrong SphericalCoords coordinates.";
47  throw ValueException(msg.c_str());
48  }
49  }
50  v_[0] = r;
51  v_[1] = theta;
52  v_[2] = psi;
53  }
54 
55  double operator[](unsigned int i) const {
56  IMP_USAGE_CHECK(i < 3, "Invalid component of SphericalCoords requested: "
57  << i << " of " << 3);
58  return v_[i];
59  }
60 
61  double& operator[](unsigned int i) {
62  IMP_USAGE_CHECK(i < 3, "Invalid component of SphericalCoords requested: "
63  << i << " of " << 3);
64  return v_[i];
65  }
66 
67  //! Returns a vector with the Cartesian coordinates
68  Vector3D get_cartesian_coordinates() const;
69 
70  IMP_SHOWABLE_INLINE(SphericalVector3D, out << v_[0] << " , " << v_[1] << " , "
71  << v_[2]);
72 
73  private:
74  void set_cartesian_coordinates(const Vector3D& v);
75  double v_[3];
76 };
77 
79 
80 IMPALGEBRA_END_NAMESPACE
81 
82 #endif /* IMPALGEBRA_SPHERICAL_VECTOR_3D_H */
Base class for geometric types.
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
Exception definitions and assertions.
A more IMP-like version of the std::vector.
Definition: Vector.h:39
SphericalVector3D(const Vector3D &v)
Construct from a Cartesian coordinate vector.
#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)
Construct from provided spherical coordinates.
Various useful constants.
Class to represent a 3D point in spherical coordinates.
VectorD< 3 > Vector3D
Definition: VectorD.h:421
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:168
An exception for an invalid value being passed to IMP.
Definition: exception.h:137
std::string String
Basic string value.
Definition: types.h:44
Various general useful macros for IMP.