Wm4Math.inl

Go to the documentation of this file.
00001 // Wild Magic Source Code
00002 // David Eberly
00003 // http://www.geometrictools.com
00004 // Copyright (c) 1998-2007
00005 //
00006 // This library is free software; you can redistribute it and/or modify it
00007 // under the terms of the GNU Lesser General Public License as published by
00008 // the Free Software Foundation; either version 2.1 of the License, or (at
00009 // your option) any later version.  The license is available for reading at
00010 // either of the locations:
00011 //     http://www.gnu.org/copyleft/lgpl.html
00012 //     http://www.geometrictools.com/License/WildMagicLicense.pdf
00013 // The license applies to versions 0 through 4 of Wild Magic.
00014 //
00015 // Version: 4.0.1 (2006/08/22)
00016 
00017 namespace Wm4
00018 {
00019 //----------------------------------------------------------------------------
00020 template <class Real>
00021 Real Math<Real>::ACos (Real fValue)
00022 {
00023     if (-(Real)1.0 < fValue)
00024     {
00025         if (fValue < (Real)1.0)
00026         {
00027             return (Real)acos((double)fValue);
00028         }
00029         else
00030         {
00031             return (Real)0.0;
00032         }
00033     }
00034     else
00035     {
00036         return PI;
00037     }
00038 }
00039 //----------------------------------------------------------------------------
00040 template <class Real>
00041 Real Math<Real>::ASin (Real fValue)
00042 {
00043     if (-(Real)1.0 < fValue)
00044     {
00045         if (fValue < (Real)1.0)
00046         {
00047             return (Real)asin((double)fValue);
00048         }
00049         else
00050         {
00051             return HALF_PI;
00052         }
00053     }
00054     else
00055     {
00056         return -HALF_PI;
00057     }
00058 }
00059 //----------------------------------------------------------------------------
00060 template <class Real>
00061 Real Math<Real>::ATan (Real fValue)
00062 {
00063     return (Real)atan((double)fValue);
00064 }
00065 //----------------------------------------------------------------------------
00066 template <class Real>
00067 Real Math<Real>::ATan2 (Real fY, Real fX)
00068 {
00069     return (Real)atan2((double)fY,(double)fX);
00070 }
00071 //----------------------------------------------------------------------------
00072 template <class Real>
00073 Real Math<Real>::Ceil (Real fValue)
00074 {
00075     return (Real)ceil((double)fValue);
00076 }
00077 //----------------------------------------------------------------------------
00078 template <class Real>
00079 Real Math<Real>::Cos (Real fValue)
00080 {
00081     return (Real)cos((double)fValue);
00082 }
00083 //----------------------------------------------------------------------------
00084 template <class Real>
00085 Real Math<Real>::Exp (Real fValue)
00086 {
00087     return (Real)exp((double)fValue);
00088 }
00089 //----------------------------------------------------------------------------
00090 template <class Real>
00091 Real Math<Real>::FAbs (Real fValue)
00092 {
00093     return (Real)fabs((double)fValue);
00094 }
00095 //----------------------------------------------------------------------------
00096 template <class Real>
00097 Real Math<Real>::Floor (Real fValue)
00098 {
00099     return (Real)floor((double)fValue);
00100 }
00101 //----------------------------------------------------------------------------
00102 template <class Real>
00103 Real Math<Real>::FMod (Real fX, Real fY)
00104 {
00105     return (Real)fmod((double)fX,(double)fY);
00106 }
00107 //----------------------------------------------------------------------------
00108 template <class Real>
00109 Real Math<Real>::InvSqrt (Real fValue)
00110 {
00111     return (Real)(1.0/sqrt((double)fValue));
00112 }
00113 //----------------------------------------------------------------------------
00114 template <class Real>
00115 Real Math<Real>::Log (Real fValue)
00116 {
00117     return (Real)log((double)fValue);
00118 }
00119 //----------------------------------------------------------------------------
00120 template <class Real>
00121 Real Math<Real>::Log2 (Real fValue)
00122 {
00123     return Math<Real>::INV_LN_2 * (Real)log((double)fValue);
00124 }
00125 //----------------------------------------------------------------------------
00126 template <class Real>
00127 Real Math<Real>::Log10 (Real fValue)
00128 {
00129     return Math<Real>::INV_LN_10 * (Real)log((double)fValue);
00130 }
00131 //----------------------------------------------------------------------------
00132 template <class Real>
00133 Real Math<Real>::Pow (Real fBase, Real fExponent)
00134 {
00135     return (Real)pow((double)fBase,(double)fExponent);
00136 }
00137 //----------------------------------------------------------------------------
00138 template <class Real>
00139 Real Math<Real>::Sin (Real fValue)
00140 {
00141     return (Real)sin((double)fValue);
00142 }
00143 //----------------------------------------------------------------------------
00144 template <class Real>
00145 Real Math<Real>::Sqr (Real fValue)
00146 {
00147     return fValue*fValue;
00148 }
00149 //----------------------------------------------------------------------------
00150 template <class Real>
00151 Real Math<Real>::Sqrt (Real fValue)
00152 {
00153     return (Real)sqrt((double)fValue);
00154 }
00155 //----------------------------------------------------------------------------
00156 template <class Real>
00157 Real Math<Real>::Tan (Real fValue)
00158 {
00159     return (Real)tan((double)fValue);
00160 }
00161 //----------------------------------------------------------------------------
00162 template <class Real>
00163 int Math<Real>::Sign (int iValue)
00164 {
00165     if (iValue > 0)
00166     {
00167         return 1;
00168     }
00169 
00170     if (iValue < 0)
00171     {
00172         return -1;
00173     }
00174 
00175     return 0;
00176 }
00177 //----------------------------------------------------------------------------
00178 template <class Real>
00179 Real Math<Real>::Sign (Real fValue)
00180 {
00181     if (fValue > (Real)0.0)
00182     {
00183         return (Real)1.0;
00184     }
00185 
00186     if (fValue < (Real)0.0)
00187     {
00188         return -(Real)1.0;
00189     }
00190 
00191     return (Real)0.0;
00192 }
00193 //----------------------------------------------------------------------------
00194 template <class Real>
00195 Real Math<Real>::UnitRandom (unsigned int uiSeed )
00196 {
00197     if (uiSeed > 0)
00198     {
00199         srand(uiSeed);
00200     }
00201 
00202     double dRatio = ((double)rand())/((double)(RAND_MAX));
00203     return (Real)dRatio;
00204 }
00205 //----------------------------------------------------------------------------
00206 template <class Real>
00207 Real Math<Real>::SymmetricRandom (unsigned int uiSeed)
00208 {
00209     if (uiSeed > 0.0)
00210     {
00211         srand(uiSeed);
00212     }
00213 
00214     double dRatio = ((double)rand())/((double)(RAND_MAX));
00215     return (Real)(2.0*dRatio - 1.0);
00216 }
00217 //----------------------------------------------------------------------------
00218 template <class Real>
00219 Real Math<Real>::IntervalRandom (Real fMin, Real fMax, unsigned int uiSeed)
00220 {
00221     if (uiSeed > 0)
00222     {
00223         srand(uiSeed);
00224     }
00225 
00226     double dRatio = ((double)rand())/((double)(RAND_MAX));
00227     return fMin+(fMax-fMin)*((Real)dRatio);
00228 }
00229 //----------------------------------------------------------------------------
00230 template <class Real>
00231 Real Math<Real>::FastSin0 (Real fAngle)
00232 {
00233     Real fASqr = fAngle*fAngle;
00234     Real fResult = (Real)7.61e-03;
00235     fResult *= fASqr;
00236     fResult -= (Real)1.6605e-01;
00237     fResult *= fASqr;
00238     fResult += (Real)1.0;
00239     fResult *= fAngle;
00240     return fResult;
00241 }
00242 //----------------------------------------------------------------------------
00243 template <class Real>
00244 Real Math<Real>::FastSin1 (Real fAngle)
00245 {
00246     Real fASqr = fAngle*fAngle;
00247     Real fResult = -(Real)2.39e-08;
00248     fResult *= fASqr;
00249     fResult += (Real)2.7526e-06;
00250     fResult *= fASqr;
00251     fResult -= (Real)1.98409e-04;
00252     fResult *= fASqr;
00253     fResult += (Real)8.3333315e-03;
00254     fResult *= fASqr;
00255     fResult -= (Real)1.666666664e-01;
00256     fResult *= fASqr;
00257     fResult += (Real)1.0;
00258     fResult *= fAngle;
00259     return fResult;
00260 }
00261 //----------------------------------------------------------------------------
00262 template <class Real>
00263 Real Math<Real>::FastCos0 (Real fAngle)
00264 {
00265     Real fASqr = fAngle*fAngle;
00266     Real fResult = (Real)3.705e-02;
00267     fResult *= fASqr;
00268     fResult -= (Real)4.967e-01;
00269     fResult *= fASqr;
00270     fResult += (Real)1.0;
00271     return fResult;
00272 }
00273 //----------------------------------------------------------------------------
00274 template <class Real>
00275 Real Math<Real>::FastCos1 (Real fAngle)
00276 {
00277     Real fASqr = fAngle*fAngle;
00278     Real fResult = -(Real)2.605e-07;
00279     fResult *= fASqr;
00280     fResult += (Real)2.47609e-05;
00281     fResult *= fASqr;
00282     fResult -= (Real)1.3888397e-03;
00283     fResult *= fASqr;
00284     fResult += (Real)4.16666418e-02;
00285     fResult *= fASqr;
00286     fResult -= (Real)4.999999963e-01;
00287     fResult *= fASqr;
00288     fResult += (Real)1.0;
00289     return fResult;
00290 }
00291 //----------------------------------------------------------------------------
00292 template <class Real>
00293 Real Math<Real>::FastTan0 (Real fAngle)
00294 {
00295     Real fASqr = fAngle*fAngle;
00296     Real fResult = (Real)2.033e-01;
00297     fResult *= fASqr;
00298     fResult += (Real)3.1755e-01;
00299     fResult *= fASqr;
00300     fResult += (Real)1.0;
00301     fResult *= fAngle;
00302     return fResult;
00303 }
00304 //----------------------------------------------------------------------------
00305 template <class Real>
00306 Real Math<Real>::FastTan1 (Real fAngle)
00307 {
00308     Real fASqr = fAngle*fAngle;
00309     Real fResult = (Real)9.5168091e-03;
00310     fResult *= fASqr;
00311     fResult += (Real)2.900525e-03;
00312     fResult *= fASqr;
00313     fResult += (Real)2.45650893e-02;
00314     fResult *= fASqr;
00315     fResult += (Real)5.33740603e-02;
00316     fResult *= fASqr;
00317     fResult += (Real)1.333923995e-01;
00318     fResult *= fASqr;
00319     fResult += (Real)3.333314036e-01;
00320     fResult *= fASqr;
00321     fResult += (Real)1.0;
00322     fResult *= fAngle;
00323     return fResult;
00324 }
00325 //----------------------------------------------------------------------------
00326 template <class Real>
00327 Real Math<Real>::FastInvSin0 (Real fValue)
00328 {
00329     Real fRoot = Math<Real>::Sqrt(((Real)1.0)-fValue);
00330     Real fResult = -(Real)0.0187293;
00331     fResult *= fValue;
00332     fResult += (Real)0.0742610;
00333     fResult *= fValue;
00334     fResult -= (Real)0.2121144;
00335     fResult *= fValue;
00336     fResult += (Real)1.5707288;
00337     fResult = HALF_PI - fRoot*fResult;
00338     return fResult;
00339 }
00340 //----------------------------------------------------------------------------
00341 template <class Real>
00342 Real Math<Real>::FastInvSin1 (Real fValue)
00343 {
00344     Real fRoot = Math<Real>::Sqrt(FAbs(((Real)1.0)-fValue));
00345     Real fResult = -(Real)0.0012624911;
00346     fResult *= fValue;
00347     fResult += (Real)0.0066700901;
00348     fResult *= fValue;
00349     fResult -= (Real)0.0170881256;
00350     fResult *= fValue;
00351     fResult += (Real)0.0308918810;
00352     fResult *= fValue;
00353     fResult -= (Real)0.0501743046;
00354     fResult *= fValue;
00355     fResult += (Real)0.0889789874;
00356     fResult *= fValue;
00357     fResult -= (Real)0.2145988016;
00358     fResult *= fValue;
00359     fResult += (Real)1.5707963050;
00360     fResult = HALF_PI - fRoot*fResult;
00361     return fResult;
00362 }
00363 //----------------------------------------------------------------------------
00364 template <class Real>
00365 Real Math<Real>::FastInvCos0 (Real fValue)
00366 {
00367     Real fRoot = Math<Real>::Sqrt(((Real)1.0)-fValue);
00368     Real fResult = -(Real)0.0187293;
00369     fResult *= fValue;
00370     fResult += (Real)0.0742610;
00371     fResult *= fValue;
00372     fResult -= (Real)0.2121144;
00373     fResult *= fValue;
00374     fResult += (Real)1.5707288;
00375     fResult *= fRoot;
00376     return fResult;
00377 }
00378 //----------------------------------------------------------------------------
00379 template <class Real>
00380 Real Math<Real>::FastInvCos1 (Real fValue)
00381 {
00382     Real fRoot = Math<Real>::Sqrt(FAbs(((Real)1.0)-fValue));
00383     Real fResult = -(Real)0.0012624911;
00384     fResult *= fValue;
00385     fResult += (Real)0.0066700901;
00386     fResult *= fValue;
00387     fResult -= (Real)0.0170881256;
00388     fResult *= fValue;
00389     fResult += (Real)0.0308918810;
00390     fResult *= fValue;
00391     fResult -= (Real)0.0501743046;
00392     fResult *= fValue;
00393     fResult += (Real)0.0889789874;
00394     fResult *= fValue;
00395     fResult -= (Real)0.2145988016;
00396     fResult *= fValue;
00397     fResult += (Real)1.5707963050;
00398     fResult *= fRoot;
00399     return fResult;
00400 }
00401 //----------------------------------------------------------------------------
00402 template <class Real>
00403 Real Math<Real>::FastInvTan0 (Real fValue)
00404 {
00405     Real fVSqr = fValue*fValue;
00406     Real fResult = (Real)0.0208351;
00407     fResult *= fVSqr;
00408     fResult -= (Real)0.085133;
00409     fResult *= fVSqr;
00410     fResult += (Real)0.180141;
00411     fResult *= fVSqr;
00412     fResult -= (Real)0.3302995;
00413     fResult *= fVSqr;
00414     fResult += (Real)0.999866;
00415     fResult *= fValue;
00416     return fResult;
00417 }
00418 //----------------------------------------------------------------------------
00419 template <class Real>
00420 Real Math<Real>::FastInvTan1 (Real fValue)
00421 {
00422     Real fVSqr = fValue*fValue;
00423     Real fResult = (Real)0.0028662257;
00424     fResult *= fVSqr;
00425     fResult -= (Real)0.0161657367;
00426     fResult *= fVSqr;
00427     fResult += (Real)0.0429096138;
00428     fResult *= fVSqr;
00429     fResult -= (Real)0.0752896400;
00430     fResult *= fVSqr;
00431     fResult += (Real)0.1065626393;
00432     fResult *= fVSqr;
00433     fResult -= (Real)0.1420889944;
00434     fResult *= fVSqr;
00435     fResult += (Real)0.1999355085;
00436     fResult *= fVSqr;
00437     fResult -= (Real)0.3333314528;
00438     fResult *= fVSqr;
00439     fResult += (Real)1.0;
00440     fResult *= fValue;
00441     return fResult;
00442 }
00443 //----------------------------------------------------------------------------
00444 template <class Real>
00445 Real Math<Real>::FastNegExp0 (Real fValue)
00446 {
00447     Real fResult = (Real)0.0038278;
00448     fResult *= fValue;
00449     fResult += (Real)0.0292732;
00450     fResult *= fValue;
00451     fResult += (Real)0.2507213;
00452     fResult *= fValue;
00453     fResult += (Real)1.0;
00454     fResult *= fResult;
00455     fResult *= fResult;
00456     fResult = ((Real)1.0)/fResult;
00457     return fResult;
00458 }
00459 //----------------------------------------------------------------------------
00460 template <class Real>
00461 Real Math<Real>::FastNegExp1 (Real fValue)
00462 {
00463     Real fResult = (Real)0.00026695;
00464     fResult *= fValue;
00465     fResult += (Real)0.00227723;
00466     fResult *= fValue;
00467     fResult += (Real)0.03158565;
00468     fResult *= fValue;
00469     fResult += (Real)0.24991035;
00470     fResult *= fValue;
00471     fResult += (Real)1.0;
00472     fResult *= fResult;
00473     fResult *= fResult;
00474     fResult = ((Real)1.0)/fResult;
00475     return fResult;
00476 }
00477 //----------------------------------------------------------------------------
00478 template <class Real>
00479 Real Math<Real>::FastNegExp2 (Real fValue)
00480 {
00481     Real fResult = (Real)0.000014876;
00482     fResult *= fValue;
00483     fResult += (Real)0.000127992;
00484     fResult *= fValue;
00485     fResult += (Real)0.002673255;
00486     fResult *= fValue;
00487     fResult += (Real)0.031198056;
00488     fResult *= fValue;
00489     fResult += (Real)0.250010936;
00490     fResult *= fValue;
00491     fResult += (Real)1.0;
00492     fResult *= fResult;
00493     fResult *= fResult;
00494     fResult = ((Real)1.0)/fResult;
00495     return fResult;
00496 }
00497 //----------------------------------------------------------------------------
00498 template <class Real>
00499 Real Math<Real>::FastNegExp3 (Real fValue)
00500 {
00501     Real fResult = (Real)0.0000006906;
00502     fResult *= fValue;
00503     fResult += (Real)0.0000054302;
00504     fResult *= fValue;
00505     fResult += (Real)0.0001715620;
00506     fResult *= fValue;
00507     fResult += (Real)0.0025913712;
00508     fResult *= fValue;
00509     fResult += (Real)0.0312575832;
00510     fResult *= fValue;
00511     fResult += (Real)0.2499986842;
00512     fResult *= fValue;
00513     fResult += (Real)1.0;
00514     fResult *= fResult;
00515     fResult *= fResult;
00516     fResult = ((Real)1.0)/fResult;
00517     return fResult;
00518 }
00519 //----------------------------------------------------------------------------
00520 } // namespace Wm4

Generated on Wed Nov 23 19:01:04 2011 for FreeCAD by  doxygen 1.6.1