00001 /** @file geom/geom.h geometry helper functions for manipulating 00002 angles, converting degrees/radians */ 00003 00004 /////////////////////////////////////////////////////////////////////// 00005 // 00006 // Copyright (c) 2002-2004 California Institute of Technology 00007 // Copyright (c) 2004-2007 University of Southern California 00008 // Rob Peters <rjpeters at usc dot edu> 00009 // 00010 // created: Mon May 12 11:16:03 2003 00011 // commit: $Id: geom.h 9078 2007-12-11 21:11:45Z rjpeters $ 00012 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Image/geom.h $ 00013 // 00014 // -------------------------------------------------------------------- 00015 // 00016 // This file is part of GroovX. 00017 // [http://ilab.usc.edu/rjpeters/groovx/] 00018 // 00019 // GroovX is free software; you can redistribute it and/or modify it 00020 // under the terms of the GNU General Public License as published by 00021 // the Free Software Foundation; either version 2 of the License, or 00022 // (at your option) any later version. 00023 // 00024 // GroovX is distributed in the hope that it will be useful, but 00025 // WITHOUT ANY WARRANTY; without even the implied warranty of 00026 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00027 // General Public License for more details. 00028 // 00029 // You should have received a copy of the GNU General Public License 00030 // along with GroovX; if not, write to the Free Software Foundation, 00031 // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 00032 // 00033 /////////////////////////////////////////////////////////////////////// 00034 00035 #ifndef GROOVX_GEOM_GEOM_H_UTC20050626084022_DEFINED 00036 #define GROOVX_GEOM_GEOM_H_UTC20050626084022_DEFINED 00037 00038 #include <cmath> 00039 00040 namespace geom 00041 { 00042 inline double deg2rad(double degrees) 00043 { 00044 return degrees * M_PI/180.0; 00045 } 00046 00047 inline double rad2deg(double radians) 00048 { 00049 return radians * 180.0/M_PI; 00050 } 00051 00052 inline double deg_n180_180(double degrees) 00053 { 00054 while (degrees > 180.0) { degrees -= 360.0; } 00055 while (degrees <= -180.0) { degrees += 360.0; } 00056 00057 return degrees; 00058 } 00059 00060 inline double rad_0_2pi(double angle) 00061 { 00062 while (angle < 0.0) angle += 2*M_PI; 00063 while (angle >= 2*M_PI) angle -= 2*M_PI; 00064 00065 return angle; 00066 } 00067 00068 inline double rad_npi_pi(double angle) 00069 { 00070 while (angle < -M_PI) angle += 2*M_PI; 00071 while (angle >= M_PI) angle -= 2*M_PI; 00072 00073 return angle; 00074 } 00075 00076 inline double rad_0_pi(double angle) 00077 { 00078 while (angle < 0.0) angle += M_PI; 00079 while (angle >= M_PI) angle -= M_PI; 00080 00081 return angle; 00082 } 00083 } 00084 00085 static const char __attribute__((used)) vcid_groovx_geom_geom_h_utc20050626084022[] = "$Id: geom.h 9078 2007-12-11 21:11:45Z rjpeters $ $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Image/geom.h $"; 00086 #endif // !GROOVX_GEOM_GEOM_H_UTC20050626084022_DEFINED