From 1ec55e880489b3c42e4b323f2f7b0f36f556cf01 Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Fri, 10 Apr 2020 00:34:55 +0200 Subject: [PATCH] Add GSkyDir::rotate() method --- NEWS | 1 + include/GSkyDir.hpp | 3 ++- pyext/GSkyDir.i | 3 ++- src/sky/GSkyDir.cpp | 41 ++++++++++++++++++++++++++++++++--------- 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/NEWS b/NEWS index a6b8670..067d9d8 100644 --- a/NEWS +++ b/NEWS @@ -34,6 +34,7 @@ The following methods have been added: - GSkyDir::precess() - Precess sky position to epoch - GSkyDir::sun() - Set sky position of Sun - GSkyDir::moon() - Set sky position of Moon +- GSkyDir::rotate() - Rotate sky direction (radians variant) - GSkyMap::extract() - Extract section of sky map - GModelSpatial::flux() - Extract flux from sky region - GCTAObservation::remove_response_cache(string&) - Remove response cache for model diff --git a/include/GSkyDir.hpp b/include/GSkyDir.hpp index d141c44..6965a17 100644 --- a/include/GSkyDir.hpp +++ b/include/GSkyDir.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * GSkyDir.hpp - Sky direction class * * ----------------------------------------------------------------------- * - * copyright (C) 2008-2019 by Juergen Knoedlseder * + * copyright (C) 2008-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -83,6 +83,7 @@ public: void lb(const double& l, const double& b); void lb_deg(const double& l, const double& b); void celvector(const GVector& vector); + void rotate(const double& phi, const double& theta); void rotate_deg(const double& phi, const double& theta); void precess(const double& from_epoch, const double& to_epoch); void sun(const GTime& time, const double& epoch = 2000.0); diff --git a/pyext/GSkyDir.i b/pyext/GSkyDir.i index c75a8b6..092980b 100644 --- a/pyext/GSkyDir.i +++ b/pyext/GSkyDir.i @@ -1,7 +1,7 @@ /*************************************************************************** * GSkyDir.i - Sky direction class * * ----------------------------------------------------------------------- * - * copyright (C) 2008-2019 by Juergen Knoedlseder * + * copyright (C) 2008-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -51,6 +51,7 @@ public: void lb(const double& l, const double& b); void lb_deg(const double& l, const double& b); void celvector(const GVector& vector); + void rotate(const double& phi, const double& theta); void rotate_deg(const double& phi, const double& theta); void precess(const double& from_epoch, const double& to_epoch); void sun(const GTime& time, const double& epoch = gammalib::epoch2000); diff --git a/src/sky/GSkyDir.cpp b/src/sky/GSkyDir.cpp index ce1e0d1..0d37ff7 100644 --- a/src/sky/GSkyDir.cpp +++ b/src/sky/GSkyDir.cpp @@ -310,15 +310,15 @@ void GSkyDir::celvector(const GVector& vector) /***********************************************************************//** * @brief Rotate sky direction by zenith and azimuth angle * - * @param[in] phi Azimuth angle (deg). - * @param[in] theta Zenith angle (deg). + * @param[in] phi Azimuth angle (radians). + * @param[in] theta Zenith angle (radians). * * Rotate sky direction by a zenith and azimuth angle given in the system * of the sky direction and aligned in celestial coordinates. * The azimuth angle is counted counter clockwise from celestial north * (this is identical to the astronomical definition of a position angle). ***************************************************************************/ -void GSkyDir::rotate_deg(const double& phi, const double& theta) +void GSkyDir::rotate(const double& phi, const double& theta) { // If we have no equatorial coordinates then get them now if (!m_has_radec && m_has_lb) { @@ -336,12 +336,10 @@ void GSkyDir::rotate_deg(const double& phi, const double& theta) GMatrix rot = (ry * rz).transpose(); // Set up native coordinate vector - double phi_rad = phi * gammalib::deg2rad; - double theta_rad = theta * gammalib::deg2rad; - double cos_phi = std::cos(phi_rad); - double sin_phi = std::sin(phi_rad); - double cos_theta = std::cos(theta_rad); - double sin_theta = std::sin(theta_rad); + double cos_phi = std::cos(phi); + double sin_phi = std::sin(phi); + double cos_theta = std::cos(theta); + double sin_theta = std::sin(theta); GVector native(-cos_phi*sin_theta, sin_phi*sin_theta, cos_theta); // Rotate vector into celestial coordinates @@ -356,6 +354,31 @@ void GSkyDir::rotate_deg(const double& phi, const double& theta) /***********************************************************************//** + * @brief Rotate sky direction by zenith and azimuth angle + * + * @param[in] phi Azimuth angle (deg). + * @param[in] theta Zenith angle (deg). + * + * Rotate sky direction by a zenith and azimuth angle given in the system + * of the sky direction and aligned in celestial coordinates. + * The azimuth angle is counted counter clockwise from celestial north + * (this is identical to the astronomical definition of a position angle). + ***************************************************************************/ +void GSkyDir::rotate_deg(const double& phi, const double& theta) +{ + // Convert phi and theta in radians + double phi_rad = phi * gammalib::deg2rad; + double theta_rad = theta * gammalib::deg2rad; + + // Rotate + rotate(phi, theta); + + // Return + return; +} + + +/***********************************************************************//** * @brief Precess sky direction * * @param[in] from_epoch Epoch of the current coordinate. -- libgit2 0.21.4