/*************************************************************************** * Copyright (C) 2012 by Nicolas PASCAL * * nicolas.pascal@icare.univ-lille1.fr * * * * 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. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ /*************************************************************************** * Descrition : * * implements common geometry constants and functions * * * * History : * * 2012/02/03 : start * ***************************************************************************/ #ifndef GEOMETRY_COMMON_H #define GEOMETRY_COMMON_H #include /** PI multiplied by 2 */ static const double M_2PI = 2. * M_PI; /** PI divided by 2 */ // static const double M_PI_2 = M_PI / 2.; /** degrees to radians conversion constant */ const double DEG2RAD = double ( M_PI ) / double ( 180.); /** radians to degrees conversion constant */ const double RAD2DEG = double ( 180. ) * double ( M_1_PI ); /** * @brief convert an angle in degrees to radians * @param degrees angle to convert in degrees * @return angle in radians */ inline const double radians (const double alpha) { return DEG2RAD * alpha; }; /** * @brief convert an angle in radians to degrees * @param radians angle to convert in radians * @return angle in degrees */ inline const double degrees (const double alpha) { return RAD2DEG * alpha; }; /** * @brief format a latitude to be in the range [-90, 90] * @param lat any latitude * @return the latitude in the range [-90, 90] */ inline double format_lat (double lat) { while (lat < - 90.) lat = -180. - lat; while (lat > 90.) lat = 180. - lat; return lat; }; /** * @brief format a longitude to be in the range [-180, 180[ * @param lon any longitude * @return the longitude in the range [-180, 180[ */ inline double format_lon (double lon) { while (lon < - 180.) lon += 360.; while (lon >= 180.) lon -= 360.; return lon; }; #endif