Commit 1ec55e880489b3c42e4b323f2f7b0f36f556cf01
1 parent
d511521a
Add GSkyDir::rotate() method
Showing
4 changed files
with
37 additions
and
11 deletions
NEWS
| ... | ... | @@ -34,6 +34,7 @@ The following methods have been added: |
| 34 | 34 | - GSkyDir::precess() - Precess sky position to epoch |
| 35 | 35 | - GSkyDir::sun() - Set sky position of Sun |
| 36 | 36 | - GSkyDir::moon() - Set sky position of Moon |
| 37 | +- GSkyDir::rotate() - Rotate sky direction (radians variant) | |
| 37 | 38 | - GSkyMap::extract() - Extract section of sky map |
| 38 | 39 | - GModelSpatial::flux() - Extract flux from sky region |
| 39 | 40 | - GCTAObservation::remove_response_cache(string&) - Remove response cache for model | ... | ... |
include/GSkyDir.hpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GSkyDir.hpp - Sky direction class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2008-2019 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2008-2020 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -83,6 +83,7 @@ public: |
| 83 | 83 | void lb(const double& l, const double& b); |
| 84 | 84 | void lb_deg(const double& l, const double& b); |
| 85 | 85 | void celvector(const GVector& vector); |
| 86 | + void rotate(const double& phi, const double& theta); | |
| 86 | 87 | void rotate_deg(const double& phi, const double& theta); |
| 87 | 88 | void precess(const double& from_epoch, const double& to_epoch); |
| 88 | 89 | void sun(const GTime& time, const double& epoch = 2000.0); | ... | ... |
pyext/GSkyDir.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GSkyDir.i - Sky direction class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2008-2019 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2008-2020 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -51,6 +51,7 @@ public: |
| 51 | 51 | void lb(const double& l, const double& b); |
| 52 | 52 | void lb_deg(const double& l, const double& b); |
| 53 | 53 | void celvector(const GVector& vector); |
| 54 | + void rotate(const double& phi, const double& theta); | |
| 54 | 55 | void rotate_deg(const double& phi, const double& theta); |
| 55 | 56 | void precess(const double& from_epoch, const double& to_epoch); |
| 56 | 57 | void sun(const GTime& time, const double& epoch = gammalib::epoch2000); | ... | ... |
src/sky/GSkyDir.cpp
| ... | ... | @@ -310,15 +310,15 @@ void GSkyDir::celvector(const GVector& vector) |
| 310 | 310 | /***********************************************************************//** |
| 311 | 311 | * @brief Rotate sky direction by zenith and azimuth angle |
| 312 | 312 | * |
| 313 | - * @param[in] phi Azimuth angle (deg). | |
| 314 | - * @param[in] theta Zenith angle (deg). | |
| 313 | + * @param[in] phi Azimuth angle (radians). | |
| 314 | + * @param[in] theta Zenith angle (radians). | |
| 315 | 315 | * |
| 316 | 316 | * Rotate sky direction by a zenith and azimuth angle given in the system |
| 317 | 317 | * of the sky direction and aligned in celestial coordinates. |
| 318 | 318 | * The azimuth angle is counted counter clockwise from celestial north |
| 319 | 319 | * (this is identical to the astronomical definition of a position angle). |
| 320 | 320 | ***************************************************************************/ |
| 321 | -void GSkyDir::rotate_deg(const double& phi, const double& theta) | |
| 321 | +void GSkyDir::rotate(const double& phi, const double& theta) | |
| 322 | 322 | { |
| 323 | 323 | // If we have no equatorial coordinates then get them now |
| 324 | 324 | if (!m_has_radec && m_has_lb) { |
| ... | ... | @@ -336,12 +336,10 @@ void GSkyDir::rotate_deg(const double& phi, const double& theta) |
| 336 | 336 | GMatrix rot = (ry * rz).transpose(); |
| 337 | 337 | |
| 338 | 338 | // Set up native coordinate vector |
| 339 | - double phi_rad = phi * gammalib::deg2rad; | |
| 340 | - double theta_rad = theta * gammalib::deg2rad; | |
| 341 | - double cos_phi = std::cos(phi_rad); | |
| 342 | - double sin_phi = std::sin(phi_rad); | |
| 343 | - double cos_theta = std::cos(theta_rad); | |
| 344 | - double sin_theta = std::sin(theta_rad); | |
| 339 | + double cos_phi = std::cos(phi); | |
| 340 | + double sin_phi = std::sin(phi); | |
| 341 | + double cos_theta = std::cos(theta); | |
| 342 | + double sin_theta = std::sin(theta); | |
| 345 | 343 | GVector native(-cos_phi*sin_theta, sin_phi*sin_theta, cos_theta); |
| 346 | 344 | |
| 347 | 345 | // Rotate vector into celestial coordinates |
| ... | ... | @@ -356,6 +354,31 @@ void GSkyDir::rotate_deg(const double& phi, const double& theta) |
| 356 | 354 | |
| 357 | 355 | |
| 358 | 356 | /***********************************************************************//** |
| 357 | + * @brief Rotate sky direction by zenith and azimuth angle | |
| 358 | + * | |
| 359 | + * @param[in] phi Azimuth angle (deg). | |
| 360 | + * @param[in] theta Zenith angle (deg). | |
| 361 | + * | |
| 362 | + * Rotate sky direction by a zenith and azimuth angle given in the system | |
| 363 | + * of the sky direction and aligned in celestial coordinates. | |
| 364 | + * The azimuth angle is counted counter clockwise from celestial north | |
| 365 | + * (this is identical to the astronomical definition of a position angle). | |
| 366 | + ***************************************************************************/ | |
| 367 | +void GSkyDir::rotate_deg(const double& phi, const double& theta) | |
| 368 | +{ | |
| 369 | + // Convert phi and theta in radians | |
| 370 | + double phi_rad = phi * gammalib::deg2rad; | |
| 371 | + double theta_rad = theta * gammalib::deg2rad; | |
| 372 | + | |
| 373 | + // Rotate | |
| 374 | + rotate(phi, theta); | |
| 375 | + | |
| 376 | + // Return | |
| 377 | + return; | |
| 378 | +} | |
| 379 | + | |
| 380 | + | |
| 381 | +/***********************************************************************//** | |
| 359 | 382 | * @brief Precess sky direction |
| 360 | 383 | * |
| 361 | 384 | * @param[in] from_epoch Epoch of the current coordinate. | ... | ... |