⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 maths.cpp

📁 该程序实现FIRE足球机器人竞赛中的3:3比赛源码
💻 CPP
字号:
// Maths.cpp: implementation of the Maths class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Maths.h"
#include "Globe.h"


/*! This function returns the Maths::Sign of a give double.
1 is positive, -1 is negative
\param d1 first parameter
\return the Maths::Sign of this double */
int Maths::Sign( double d1 )
{
	return (d1>0)?1:-1;
}

/*! 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 Maths::Max( double d1, double d2 )
{
	return (d1>d2)?d1:d2;
}

/*! 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 Maths::Min( double d1, double d2 )
{
	return (d1<d2)?d1:d2;
}


/*! 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 Maths::Rad2Deg( AngRad 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 Maths::Deg2Rad( AngDeg 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 Maths::cosDeg( AngDeg x )
{
	return ( cos( 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 Maths::sinDeg( AngDeg x )
{
	return ( sin( 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 Maths::tanDeg( AngDeg x )
{
	return ( tan( 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 Maths::atanDeg( double x )
{
	return ( 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 Maths::atan2Deg( double x, double y )
{
	if( fabs( x ) < EPS && fabs( y ) < EPS )
	return ( 0.0 );

	return ( 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 Maths::acosDeg( double x )
{
	if( x >= 1 )
	return ( 0.0 );
	else if( x <= -1 )
	return ( 180.0 );

	return ( 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 Maths::asinDeg( double x )
{
	if( x >= 1 )
	return ( 90.0 );
	else if ( x <= -1 )
	return ( -90.0 );

	return ( Rad2Deg( asin( x ) ) );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -