OpalMath.h

Go to the documentation of this file.
00001 /*************************************************************************
00002 *                                                                       *
00003 * Open Physics Abstraction Layer                                        *
00004 * Copyright (C) 2004-2005                                               *
00005 * Alan Fischer  alan.fischer@gmail.com                                  *
00006 * Andres Reinot  andres@reinot.com                                      *
00007 * Tyler Streeter  tylerstreeter@gmail.com                               *
00008 * All rights reserved.                                                  *
00009 * Web: opal.sourceforge.net                                             *
00010 *                                                                       *
00011 * This library is free software; you can redistribute it and/or         *
00012 * modify it under the terms of EITHER:                                  *
00013 *   (1) The GNU Lesser General Public License as published by the Free  *
00014 *       Software Foundation; either version 2.1 of the License, or (at  *
00015 *       your option) any later version. The text of the GNU Lesser      *
00016 *       General Public License is included with this library in the     *
00017 *       file license-LGPL.txt.                                          *
00018 *   (2) The BSD-style license that is included with this library in     *
00019 *       the file license-BSD.txt.                                       *
00020 *                                                                       *
00021 * This library is distributed in the hope that it will be useful,       *
00022 * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files    *
00024 * license-LGPL.txt and license-BSD.txt for more details.                *
00025 *                                                                       *
00026 *************************************************************************/
00027 
00028 #ifndef OPAL_OPAL_MATH_H
00029 #define OPAL_OPAL_MATH_H
00030 
00031 // system headers
00032 #include <math.h>
00033 
00034 namespace opal
00035 {
00036 #ifdef OPAL_USE_DOUBLE
00037     typedef double real;
00038 #else
00039     typedef float real;
00040 #endif
00041 
00042     namespace globals
00043     {
00044         const real OPAL_PI = ( real ) 3.14159265358979323846;
00045         const real OPAL_HALF_PI = ( real ) 1.57079632679489661923;
00046         const real OPAL_ONE_THIRD = ( real ) 0.33333333333333333333;
00047         const real OPAL_EPSILON = ( real ) 0.000001;
00048     }
00049 
00051     inline real degToRad( real deg )
00052     {
00053         const real d2r = globals::OPAL_PI / ( real ) 180.0;
00054         return ( d2r * deg );
00055     }
00056 
00058     inline real radToDeg( real rad )
00059     {
00060         const real r2d = ( real ) 180.0 / globals::OPAL_PI;
00061         return ( r2d * rad );
00062     }
00063 
00065     inline real abs( real value )
00066     {
00067         return fabs( value );
00068     }
00069 
00076     inline bool areEqual( real x, real y )
00077     {
00078         real maxVal = 1;
00079 
00080         if ( opal::abs( x ) > maxVal )
00081         {
00082             maxVal = opal::abs( x );
00083         }
00084 
00085         if ( opal::abs( y ) > maxVal )
00086         {
00087             maxVal = opal::abs( y );
00088         }
00089 
00090         if ( opal::abs( x - y ) <= globals::OPAL_EPSILON * maxVal )
00091         {
00092             return true;
00093         }
00094         else
00095         {
00096             return false;
00097         }
00098     }
00099 
00101     inline real normalizeDegrees( real degrees )
00102     {
00103         while ( degrees > 180.0 )
00104         {
00105             degrees -= 360.0;
00106         }
00107         while ( degrees <= -180.0 )
00108         {
00109             degrees += 360.0;
00110         }
00111         return degrees;
00112     }
00113 }
00114 
00115 //#include "Point3r.h"
00116 //#include "Vec3r.h"
00117 //#include "Rayr.h"
00118 //#include "Matrix44r.h"
00119 //#include "Quaternion.h"
00120 
00121 #endif
00122 

Generated on Tue May 16 17:49:51 2006 for OPAL by  doxygen 1.4.6-NO