basic/geometry/geo_rangesensor/MgcMath.cpp

Go to the documentation of this file.
00001 
00002 // Magic Software, Inc.
00003 // http://www.magic-software.com
00004 // Copyright (c) 2000, All Rights Reserved
00005 //
00006 // Source code from Magic Software is supplied under the terms of a license
00007 // agreement and may not be copied or disclosed except in accordance with the
00008 // terms of that agreement.  The various license agreements may be found at
00009 // the Magic Software web site.  This file is subject to the license
00010 //
00011 // FREE SOURCE CODE
00012 // http://www.magic-software.com/License.html/free.pdf
00013 
00014 #include "MgcMath.h"
00015 #include "MgcRTLib.h"
00016 
00017 #if MGC_USE_DOUBLE
00018     const MgcReal MgcMath::INFINITY = DBL_MAX;
00019 #else
00020     const MgcReal MgcMath::INFINITY = FLT_MAX;
00021 #endif
00022 
00023 const MgcReal MgcMath::mgcPI = 4.0*atan(1.0);
00024 const MgcReal MgcMath::TWO_PI = 2.0*mgcPI;
00025 const MgcReal MgcMath::HALF_PI = 0.5*mgcPI;
00026 
00027 //----------------------------------------------------------------------------
00028 int MgcMath::IAbs (int iValue)
00029 {
00030     return ( iValue >= 0 ? iValue : -iValue );
00031 }
00032 //----------------------------------------------------------------------------
00033 int MgcMath::ICeil (double fValue)
00034 {
00035     return int(ceil(fValue));
00036 }
00037 //----------------------------------------------------------------------------
00038 int MgcMath::IFloor (double fValue)
00039 {
00040     return int(floor(fValue));
00041 }
00042 //----------------------------------------------------------------------------
00043 int MgcMath::ISign (int iValue)
00044 {
00045     return ( iValue > 0 ? +1 : ( iValue < 0 ? -1 : 0 ) );
00046 }
00047 //----------------------------------------------------------------------------
00048 MgcReal MgcMath::Abs (MgcReal fValue)
00049 {
00050     return MgcReal(fabs(fValue));
00051 }
00052 //----------------------------------------------------------------------------
00053 MgcReal MgcMath::ACos (MgcReal fValue)
00054 {
00055     if ( -1.0 < fValue )
00056     {
00057         if ( fValue < 1.0 )
00058             return MgcReal(acos(fValue));
00059         else
00060             return 0.0;
00061     }
00062     else
00063     {
00064         return mgcPI;
00065     }
00066 }
00067 //----------------------------------------------------------------------------
00068 MgcReal MgcMath::ASin (MgcReal fValue)
00069 {
00070     if ( -1.0 < fValue )
00071     {
00072         if ( fValue < 1.0 )
00073             return MgcReal(asin(fValue));
00074         else
00075             return -HALF_PI;
00076     }
00077     else
00078     {
00079         return HALF_PI;
00080     }
00081 }
00082 //----------------------------------------------------------------------------
00083 MgcReal MgcMath::ATan (MgcReal fValue)
00084 {
00085     return MgcReal(atan(fValue));
00086 }
00087 //----------------------------------------------------------------------------
00088 MgcReal MgcMath::ATan2 (MgcReal fY, MgcReal fX)
00089 {
00090     return MgcReal(atan2(fY,fX));
00091 }
00092 //----------------------------------------------------------------------------
00093 MgcReal MgcMath::Ceil (MgcReal fValue)
00094 {
00095     return MgcReal(ceil(fValue));
00096 }
00097 //----------------------------------------------------------------------------
00098 MgcReal MgcMath::Cos (MgcReal fValue)
00099 {
00100     return MgcReal(cos(fValue));
00101 }
00102 //----------------------------------------------------------------------------
00103 MgcReal MgcMath::Exp (MgcReal fValue)
00104 {
00105     return MgcReal(exp(fValue));
00106 }
00107 //----------------------------------------------------------------------------
00108 MgcReal MgcMath::Floor (MgcReal fValue)
00109 {
00110     return MgcReal(floor(fValue));
00111 }
00112 //----------------------------------------------------------------------------
00113 MgcReal MgcMath::Log (MgcReal fValue)
00114 {
00115     return MgcReal(log(fValue));
00116 }
00117 //----------------------------------------------------------------------------
00118 MgcReal MgcMath::Pow (MgcReal fBase, MgcReal fExponent)
00119 {
00120     return MgcReal(pow(fBase,fExponent));
00121 }
00122 //----------------------------------------------------------------------------
00123 MgcReal MgcMath::Sign (MgcReal fValue)
00124 {
00125     if ( fValue > 0.0 )
00126         return 1.0;
00127 
00128     if ( fValue < 0.0 )
00129         return -1.0;
00130 
00131     return 0.0;
00132 }
00133 //----------------------------------------------------------------------------
00134 MgcReal MgcMath::Sin (MgcReal fValue)
00135 {
00136     return MgcReal(sin(fValue));
00137 }
00138 //----------------------------------------------------------------------------
00139 MgcReal MgcMath::Sqr (MgcReal fValue)
00140 {
00141     return fValue*fValue;
00142 }
00143 //----------------------------------------------------------------------------
00144 MgcReal MgcMath::Sqrt (MgcReal fValue)
00145 {
00146     return MgcReal(sqrt(fValue));
00147 }
00148 //----------------------------------------------------------------------------
00149 MgcReal MgcMath::UnitRandom ()
00150 {
00151     return MgcReal(rand())/MgcReal(RAND_MAX);
00152 }
00153 //----------------------------------------------------------------------------

Generated on Sat Apr 1 21:30:31 2006 for Motion Planning Kernel by  doxygen 1.4.6-NO