angles.h

Go to the documentation of this file.
00001 /************************************************************************
00002  *                                                                      *
00003  *       Copyright 2004, Brown University, Providence, RI               *
00004  *                                                                      *
00005  *  Permission to use and modify this software and its documentation    *
00006  *  for any purpose other than its incorporation into a commercial      *
00007  *  product is hereby granted without fee. Recipient agrees not to      *
00008  *  re-distribute this software or any modifications of this            *
00009  *  software without the permission of Brown University. Brown          *
00010  *  University makes no representations or warrantees about the         *
00011  *  suitability of this software for any purpose.  It is provided       *
00012  *  "as is" without express or implied warranty. Brown University       *
00013  *  requests notification of any modifications to this software or      *
00014  *  its documentation. Notice should be sent to:                        *
00015  *                                                                      *
00016  *  To:                                                                 *
00017  *        Software Librarian                                            *
00018  *        Laboratory for Engineering Man/Machine Systems,               *
00019  *        Division of Engineering, Box D,                               *
00020  *        Brown University                                              *
00021  *        Providence, RI 02912                                          *
00022  *        Software_Librarian@lems.brown.edu                             *
00023  *                                                                      *
00024  *  We will acknowledge all electronic notifications.                   *
00025  *                                                                      *
00026  ************************************************************************/
00027 
00028 #ifndef _ANGLES_H
00029 #define _ANGLES_H
00030 
00031 #include <cmath>
00032 
00033 //##########################################################
00034 // THE ANGLE DEFINITIONS
00035 //##########################################################
00036 #ifndef M_PI
00037 #define M_PI 3.1415926535897932384626433832795
00038 #endif
00039 
00040 inline double angle0To2Pi (double angle)
00041 {
00042 #if 0  
00043   while (angle >= M_PI*2)
00044     angle -= M_PI*2;
00045   while (angle < 0)
00046     angle += M_PI*2;
00047   return angle;
00048 #else
00049   if (angle>2*M_PI)
00050       return  fmod (angle,M_PI*2);
00051    else if (angle < 0)
00052       return (2*M_PI+ fmod (angle,M_PI*2));
00053    else return angle;
00054 #endif
00055 }
00056 
00057 inline double CCW (double reference, double angle1)
00058 {
00059    double fangle1 = angle0To2Pi(angle1);
00060    double fref = angle0To2Pi(reference);
00061 
00062    if (fref > fangle1){
00063     return angle0To2Pi(2*M_PI - (fref - fangle1));
00064   }
00065    else
00066       return angle0To2Pi(fangle1 - fref); 
00067 }
00068 
00069 #endif

Generated on Wed May 5 00:06:28 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6