www.pudn.com > Math.rar > Math.h


///=========================================================================================\\\ 
///				TriAngle 3D Base Code					    ||| 
///			Soccer 3D Simulation Based on NAO Model				    ||| 
///=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-==-=-==-=-=-==-=-==-=-=-=-=-=-=-=-=-=-=-=-=-||| 
///				Author : Ali Fattahi					    ||| 
///=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-==-=-==-=-=-==-=-==-=-=-=-=-=-=-=-=-=-=-=-=-||| 
///	Comment : 									    ||| 
///	Please Fell Free To Contact Me if You Have Any Problems or Questions About The Code ||| 
///			My Email Address : ali.robocup@gmail.com			    ||| 
///=========================================================================================/// 
 
#include  
#include  
#include  
 
#define EPSILON 0.0001  /*!< Value used for floating point equality tests. */ 
 
using namespace std; 
 
typedef double AngRad;  /*!< Type definition for angles in degrees. */ 
typedef double AngDeg;  /*!< Type definition for angles in radians. */ 
 
/*! This function returns the maximum of two given doubles. 
    \param d1 first parameter 
    \param d2 second parameter 
    \return the maximum of these two parameters */ 
double   max ( double Num1,double Num2) 
{ 
         return (Num1>Num2)?Num1:Num2; 
} 
//========================================================================================== 
/*! This function returns the minimum of two given doubles. 
    \param d1 first parameter 
    \param d2 second parameter 
    \return the minimum of these two parameters */ 
double   min ( double Num1,double Num2) 
{ 
         return (Num11)?1:-1;          
} 
//========================================================================================== 
/*! This function converts an angle in radians to the corresponding angle in 
    degrees. 
    \param x an angle in radians 
    \return the corresponding angle in degrees */ 
AngDeg    Conver_Rad2Deg ( AndRad    x   ) 
{ 
          return ( x * 180 / M_PI); 
} 
//========================================================================================== 
/*! This function converts an angle in degrees to the corresponding angle in 
    radians. 
    \param x an angle in degrees 
    \return the corresponding angle in radians */ 
AngRad    Convert_Deg2Rad ( AndDeg    x   ) 
{ 
          return ( x * M_PI / 180 ); 
} 
//========================================================================================== 
/*! This function returns the cosine of a given angle in degrees using the 
    built-in cosine function that works with angles in radians. 
    \param x an angle in degrees 
    \return the cosine of the given angle */ 
double    CosDeg (   AngDeg x ) 
{ 
          return ( cos(Convert_Deg2Rad(x)) ); 
} 
//========================================================================================== 
/*! This function returns the sine of a given angle in degrees using the 
    built-in sine function that works with angles in radians. 
    \param x an angle in degrees 
    \return the sine of the given angle */ 
double    SinDeg ( AngDeg x ) 
{ 
          return (sin(Convert_Deg2Rad(x))); 
} 
//========================================================================================= 
/*! This function returns the tangent of a given angle in degrees using the 
    built-in tangent function that works with angles in radians. 
    \param x an angle in degrees 
    \return the tangent of the given angle */ 
double TanDeg( AngDeg x ) 
{ 
  return ( tan( Convert_Deg2Rad( x ) ) ); 
} 
//========================================================================================= 
/*! This function returns the principal value of the arc tangent of x 
    in degrees using the built-in arc tangent function which returns 
    this value in radians. 
    \param x a double value 
    \return the arc tangent of the given value in degrees */ 
AngDeg aTanDeg( double x ) 
{ 
  return ( Convert_Rad2Deg( atan( x ) ) ); 
} 
//======================================================================================== 
/*! This function returns the principal value of the arc tangent of y/x in 
    degrees using the signs of both arguments to determine the quadrant of the 
    return value. For this the built-in 'atan2' function is used which returns 
    this value in radians. 
    \param x a double value 
    \param y a double value 
    \return the arc tangent of y/x in degrees taking the signs of x and y into 
    account */ 
double aTan2Deg( double x, double y ) 
{ 
  if( fabs( x ) < EPSILON && fabs( y ) < EPSILON ) 
    return ( 0.0 ); 
 
  return ( Convert_Rad2Deg( atan2( x, y ) ) ); 
} 
//======================================================================================= 
/*! This function returns the principal value of the arc cosine of x in degrees 
    using the built-in arc cosine function which returns this value in radians. 
    \param x a double value 
    \return the arc cosine of the given value in degrees */ 
AngDeg aCosDeg( double x ) 
{ 
  if( x >= 1 ) 
    return ( 0.0 ); 
  else if( x <= -1 ) 
    return ( 180.0 ); 
 
  return ( Convert_Rad2Deg( acos( x ) ) ); 
} 
///====================================================================================== 
/*! This function returns the principal value of the arc sine of x in degrees 
    using the built-in arc sine function which returns this value in radians. 
    \param x a double value 
    \return the arc sine of the given value in degrees */ 
AngDeg aSinDeg( double x ) 
{ 
  if( x >= 1 ) 
    return ( 90.0 ); 
  else if ( x <= -1 ) 
    return ( -90.0 ); 
 
  return ( Convert_Rad2Deg( asin( x ) ) ); 
} 
//======================================================================================