Commit f282b6e0750a02c75ee23628b20da6c5a6ae3d42

Authored by knodlseder
1 parent 91119fe7

add posang() and posang_deg() methods

include/GSkyDir.hpp
... ... @@ -74,6 +74,8 @@ public:
74 74 GVector celvector(void) const;
75 75 double dist(const GSkyDir& dir) const;
76 76 double dist_deg(const GSkyDir& dir) const;
  77 + double posang(const GSkyDir& dir) const;
  78 + double posang_deg(const GSkyDir& dir) const;
77 79 std::string print(void) const;
78 80  
79 81 private:
... ... @@ -86,7 +88,7 @@ private:
86 88 void euler(const int& type, const double& xin, const double &yin,
87 89 double* xout, double *yout) const;
88 90  
89   - // Private data area
  91 + // Private members
90 92 bool m_has_lb; //!< Has galactic coordinates
91 93 bool m_has_radec; //!< Has equatorial coordinates
92 94 double m_l; //!< Galactic longitude in radians
... ...
pyext/GSkyDir.i
... ... @@ -53,6 +53,8 @@ public:
53 53 GVector celvector(void) const;
54 54 double dist(const GSkyDir& dir) const;
55 55 double dist_deg(const GSkyDir& dir) const;
  56 + double posang(const GSkyDir& dir) const;
  57 + double posang_deg(const GSkyDir& dir) const;
56 58 };
57 59  
58 60  
... ...
src/sky/GSkyDir.cpp
... ... @@ -488,6 +488,75 @@ double GSkyDir::dist_deg(const GSkyDir&amp; dir) const
488 488  
489 489  
490 490 /***********************************************************************//**
  491 + * @brief Compute position angle between sky directions in radians
  492 + *
  493 + * @param[in] dir Sky direction.
  494 + *
  495 + * Computes the position angle using
  496 + * \f[PA = \arctan \left(
  497 + * \frac{\sin( \alpha_1 - \alpha_0 )}
  498 + * {\cos \delta_0 \tan \delta_1 -
  499 + * \sin \delta_0 \cos(\alpha_1 - \alpha_0)} \right)\f]
  500 + * where
  501 + * \f$(\alpha_0,\delta_0)\f$ are the coordinates of the reference point, and
  502 + * \f$(\alpha_1,\delta_1)\f$ are the coordinates of sky direction for which
  503 + * the position angle is to be computed.
  504 + *
  505 + * The position angle is counted counterclockwise from north.
  506 + ***************************************************************************/
  507 +double GSkyDir::posang(const GSkyDir& dir) const
  508 +{
  509 + // Initialise arguments of arctan
  510 + double arg_1;
  511 + double arg_2;
  512 +
  513 + // Compute dependent on coordinate system availability. This speeds
  514 + // up things by avoiding unnecessary coordinate transformations.
  515 + if (m_has_lb && dir.m_has_lb) {
  516 + arg_1 = std::sin(dir.m_l - m_l);
  517 + arg_2 = std::cos(m_b)*std::tan(dir.m_b) - std::sin(m_b)*std::cos(dir.m_l - m_l);
  518 + }
  519 + else if (m_has_radec && dir.m_has_radec) {
  520 + arg_1 = std::sin(dir.m_ra - m_ra);
  521 + arg_2 = std::cos(m_dec)*std::tan(dir.m_dec) - std::sin(m_dec)*std::cos(dir.m_ra - m_ra);
  522 + }
  523 + else if (m_has_lb) {
  524 + arg_1 = std::sin(dir.l() - m_l);
  525 + arg_2 = std::cos(m_b)*std::tan(dir.b()) - std::sin(m_b)*std::cos(dir.l() - m_l);
  526 + }
  527 + else if (m_has_radec) {
  528 + arg_1 = std::sin(dir.ra() - m_ra);
  529 + arg_2 = std::cos(m_dec)*std::tan(dir.dec()) - std::sin(m_dec)*std::cos(dir.ra() - m_ra);
  530 + }
  531 + else {
  532 + arg_1 = std::sin(dir.ra() - ra());
  533 + arg_2 = std::cos(dec())*std::tan(dir.dec()) - std::sin(dec())*std::cos(dir.ra() - ra());
  534 + }
  535 +
  536 + // Compute position angle
  537 + double pa = std::atan2(arg_1, arg_2);
  538 +
  539 + // Return position angle
  540 + return pa;
  541 +}
  542 +
  543 +
  544 +/***********************************************************************//**
  545 + * @brief Compute position angle between sky directions in degrees
  546 + *
  547 + * @param[in] dir Sky direction.
  548 + *
  549 + * See GSkyDir::posang for more information about the computation of the
  550 + * position angle.
  551 + ***************************************************************************/
  552 +double GSkyDir::posang_deg(const GSkyDir& dir) const
  553 +{
  554 + // Return position angle in degrees
  555 + return (posang(dir) * rad2deg);
  556 +}
  557 +
  558 +
  559 +/***********************************************************************//**
491 560 * @brief Print vector information
492 561 ***************************************************************************/
493 562 std::string GSkyDir::print(void) const
... ...