From f3cdb72c3b56ee5dc5019cdb9eef7fa91d6d6146 Mon Sep 17 00:00:00 2001 From: knodlseder <> Date: Wed, 2 Feb 2011 13:31:48 +0000 Subject: [PATCH] initial version --- inst/cta/src/GCTASupport.cpp | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ inst/cta/src/GCTASupport.hpp | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+), 0 deletions(-) create mode 100644 inst/cta/src/GCTASupport.cpp create mode 100644 inst/cta/src/GCTASupport.hpp diff --git a/inst/cta/src/GCTASupport.cpp b/inst/cta/src/GCTASupport.cpp new file mode 100644 index 0000000..709ea8f --- /dev/null +++ b/inst/cta/src/GCTASupport.cpp @@ -0,0 +1,89 @@ +/*************************************************************************** + * GCTASupport.cpp - CTA support functions * + * ----------------------------------------------------------------------- * + * copyright (C) 2011 by Jurgen Knodlseder * + * ----------------------------------------------------------------------- * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +/** + * @file GCTASupport.cpp + * @brief Implementation of support function used by CTA classes + * @author J. Knodlseder + */ + +/* __ Includes ___________________________________________________________ */ +#ifdef HAVE_CONFIG_H +#include +#endif +#include "GCTASupport.hpp" +#include "GTools.hpp" + +/* __ Coding definitions _________________________________________________ */ + + +/***********************************************************************//** + * @brief Returns length of circular arc within circular ROI + * + * @param[in] rad Circle radius in radians ( roi) arclength = 0.0; // Circle outside ROI + else arclength = twopi; // Circle inside ROI + } + + // ... otherwise circle and ROI centres are not identical + else { + + // Handle special case that we evaluate exactly at the circle + // centre. In this case we have in fact a point, and if this point + // falls within the ROI it has a formal arclength of 2pi. + // + if (rad == 0.0) { + if (dist > roi) arclength = 0.0; // Circle centre outside ROI + else arclength = twopi; // Circle centre inside ROI + } + + // ... otherwise we have to handle the general case + else { + double dist = roi - dist; + if (-rad >= dist) + arclength = 0.0; + else if (rad <= dist) + arclength = twopi; + else { + double cosrad = cos(rad); + double sinrad = sin(rad); + double cosang = (cosroi - cosdist*cosrad) / (sindist*sinrad); + arclength = acos(cosang); + } + } + + } // endelse: Circle and ROI centres were not identical + + // Return arclength + return arclength; +} diff --git a/inst/cta/src/GCTASupport.hpp b/inst/cta/src/GCTASupport.hpp new file mode 100644 index 0000000..8a5a8fb --- /dev/null +++ b/inst/cta/src/GCTASupport.hpp @@ -0,0 +1,33 @@ +/*************************************************************************** + * GCTASupport.hpp - CTA support functions * + * ----------------------------------------------------------------------- * + * copyright (C) 2011 by Jurgen Knodlseder * + * ----------------------------------------------------------------------- * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +/** + * @file GCTASupport.hpp + * @brief Definition of support function used by CTA classes + * @author J. Knodlseder + */ + +#ifndef GCTASUPPORT_HPP +#define GCTASUPPORT_HPP + +/* __ Includes ___________________________________________________________ */ + +/* __ Namespaces _________________________________________________________ */ + +/* __ Constants __________________________________________________________ */ + +/* __ Prototypes _________________________________________________________ */ +double cta_roi_arclength(const double& rad, const double& dist, + const double& cosdist, const double& sindist, + const double& roi, const double& cosroi); + +#endif /* GCTASUPPORT_HPP */ -- libgit2 0.21.4