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

📄 geometryr.cpp

📁 该程序实现FIRE足球机器人竞赛中的3:3比赛源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	return ( ( fabs(m_x - d) < EPS ) && ( fabs(m_y - d) < EPS ) );}/*! Overloaded version of the C++ output operator for VecPositions. Thisoperator Makes it possible to use VecPositions in output statements (e.g.cout << v). The x- and y-coordinates of the VecPosition are printed in theformat (x,y).\param os output stream to which information should be written\param v a VecPosition which must be printed\return output stream containing (x,y) *//*::ostream& operator <<( ::ostream &os, VecPosition v ){return ( os << "( " << v.m_x << ", " << v.m_y << " )" );}*//*! This method writes the current VecPosition to standard output. It can alsoprint a polar representation of the current VecPosition.\param cs a CoordSystemtT indicating whether a POLAR or CARTESIANrepresentation of the current VecPosition should be printed */void VecPosition::Show( CoordSystemT cs ){	if( cs == CARTESIAN )	printf("x = %5.2f, y = %5.2f", m_x, m_y);	else	printf("r = %5.2f, phi = %5.2f", GetMagnitude(), GetDirection( ));}
void VecPosition::Print( FILE* file )
{
	fprintf(file, "%2.2f\t%2.2f", m_x, m_y);
}

/*! This method writes the current VecPosition to a string. It can also write apolar representation of the current VecPosition.\param cs a CoordSystemtT indicating whether a POLAR or CARTESIANrepresentation of the current VecPosition should be written\return a string containing a polar or Cartesian representation of thecurrent VecPosition depending on the value of the boolean argument */void VecPosition::ToString( char buf[], CoordSystemT cs){	if( cs == CARTESIAN )	sprintf( buf, "( %5.2f, %5.2f )", GetX( ), GetY( ) );	else	sprintf( buf, "( r: %5.2f, phi: %5.2f )", GetMagnitude( ), GetDirection( ) );}/*! Set method for the x-coordinate of the current VecPosition.\param dX a double value representing a new x-coordinate\return a boolean indicating whether the Update was successful */bool VecPosition::SetX( double dX ){	m_x = dX;	return ( true );}/*! Get method for the x-coordinate of the current VecPosition.\return the x-coordinate of the current VecPosition */double VecPosition::GetX( ) const{	return ( m_x );}/*! Set method for the y-coordinate of the current VecPosition.\param dY a double value representing a new y-coordinate\return a boolean indicating whether the Update was successful */bool VecPosition::SetY( double dY ){	m_y = dY;	return ( true );}/*! Get method for the y-coordinate of the current VecPosition.\return the y-coordinate of the current VecPosition */double VecPosition::GetY( ) const{	return ( m_y );}/*! This method (re)Sets the coordinates of the current VecPosition. The givencoordinates can either be polar or Cartesian coordinates. This is indicatedby the value of the third argument.\param dX a double value indicating either a new Cartesian x-coordinate whencs=CARTESIAN or a new polar r-coordinate (distance) when cs=POLAR\param dY a double value indicating either a new Cartesian y-coordinate whencs=CARTESIAN or a new polar phi-coordinate (angle) when cs=POLAR\param cs a CoordSystemT indicating whether x and y denote cartesiancoordinates or polar coordinates */void VecPosition::SetVecPosition( double dX, double dY, CoordSystemT cs){	if( cs == CARTESIAN )	{		m_x = dX;		m_y = dY;	}	else	*this = GetVecPositionFromPolar( dX, dY );}/*! This method determines the distance between the current VecPosition and agiven VecPosition. This is equal to the magnitude (length) of the vectorconnecting the two positions which is the difference vector between them.\param p a Vecposition\return the distance between the current VecPosition and the givenVecPosition */double VecPosition::GetDistanceTo( const VecPosition p ){	return ( ( *this - p ).GetMagnitude( ) );}/*! This method adjusts the coordinates of the current VecPosition in such a waythat the magnitude of the corresponding vector equals the double value whichis supplied as an argument. It thus scales the vector to a given length bymultiplying both the x- and y-coordinates by the quotient of the argumentand the current magnitude. This changes the VecPosition itself.\param d a double value representing a new magnitude\return the result of scaling the vector corresponding with the currentVecPosition to the given magnitude thus yielding a different VecPosition */VecPosition VecPosition::SetMagnitude( double d ){	if( GetMagnitude( ) > EPS )	( *this ) *= ( d / GetMagnitude( ) );	return ( *this );}/*! This method determines the magnitude (length) of the vector correspondingwith the current VecPosition using the formula of Pythagoras.\return the length of the vector corresponding with the currentVecPosition */double VecPosition::GetMagnitude( ) const{	return ( sqrt( m_x * m_x + m_y * m_y ) );}/*! This method determines the direction of the vector corresponding with thecurrent VecPosition (the phi-coordinate in polar representation) using thearc tangent function. Note that the signs of x and y have to be taken intoaccount in order to determine the correct quadrant.\return the direction in degrees of the vector corresponding with thecurrent VecPosition */AngRad VecPosition::GetDirection( ) const{	return ( atan2( m_y, m_x ) );}/*! This method determines whether the current VecPosition is in front of agiven VecPosition, i.e. whether the x-coordinate of the current VecPositionis larger than the x-coordinate of the given VecPosition.\param p a VecPosition to which the current VecPosition must be compared\return true when the current VecPosition is in front of the givenVecPosition; false otherwise */bool VecPosition::IsRightOf( const VecPosition &p ){	return ( ( m_x >= p.GetX( ) ) ? true : false );}/*! This method determines whether the x-coordinate of the current VecPositionis in front of (i.e. larger than) a given double value.\param d a double value to which the current x-coordinate must be compared\return true when the current x-coordinate is in front of the given value;false otherwise */bool VecPosition::IsRightOf( const double &d ){	return ( ( m_x >= d ) ? true : false );}/*! This method determines whether the current VecPosition is behind a givenVecPosition, i.e. whether the x-coordinate of the current VecPosition issmaller than the x-coordinate of the given VecPosition.\param p a VecPosition to which the current VecPosition must be compared\return true when the current VecPosition is behind the given VecPosition;false otherwise */bool VecPosition::IsLeftOf( const VecPosition &p ){	return ( ( m_x <= p.GetX( ) ) ? true : false );}/*! This method determines whether the x-coordinate of the current VecPositionis behind (i.e. smaller than) a given double value.\param d a double value to which the current x-coordinate must be compared\return true when the current x-coordinate is behind the given value; falseotherwise */bool VecPosition::IsLeftOf( const double &d ){	return ( ( m_x <= d ) ? true : false );}/*! This method determines whether the current VecPosition is to the left of agiven VecPosition, i.e. whether the y-coordinate of the current VecPositionis smaller than the y-coordinate of the given VecPosition.\param p a VecPosition to which the current VecPosition must be compared\return true when the current VecPosition is to the left of the givenVecPosition; false otherwise */bool VecPosition::IsButtomOf( const VecPosition &p ){	return ( ( m_y <= p.GetY( ) ) ? true : false );}/*! This method determines whether the y-coordinate of the current VecPositionis to the left of (i.e. smaller than) a given double value.\param d a double value to which the current y-coordinate must be compared\return true when the current y-coordinate is to the left of the givenvalue; false otherwise */bool VecPosition::IsButtomOf( const double &d ){	return ( ( m_y <= d ) ? true : false );}/*! This method determines whether the current VecPosition is to the right of agiven VecPosition, i.e. whether the y-coordinate of the current VecPositionis larger than the y-coordinate of the given VecPosition.\param p a VecPosition to which the current VecPosition must be compared\return true when the current VecPosition is to the right of the givenVecPosition; false otherwise */bool VecPosition::IsTopOf( const VecPosition &p ){	return ( ( m_y >= p.GetY( ) ) ? true : false );}/*! This method determines whether the y-coordinate of the current VecPositionis to the right of (i.e. larger than) a given double value.\param d a double value to which the current y-coordinate must be compared\return true when the current y-coordinate is to the right of the givenvalue; false otherwise */bool VecPosition::IsTopOf( const double &d ){	return ( ( m_y >= d ) ? true : false );}/*! This method determines whether the current VecPosition is in between twogiven VecPositions when looking in the x-direction, i.e. whether the currentVecPosition is in front of the first argument and behind the second.\param p1 a VecPosition to which the current VecPosition must be compared\param p2 a VecPosition to which the current VecPosition must be compared\return true when the current VecPosition is in between the two givenVecPositions when looking in the x-direction; false otherwise */bool VecPosition::IsBetweenX( const VecPosition &p1, const VecPosition &p2 ){	return ( ( IsRightOf( p1 ) && IsLeftOf( p2 ) ) ? true : false );}/*! This method determines whether the x-coordinate of the current VecPositionis in between two given double values, i.e. whether the x-coordinate of thecurrent VecPosition is in front of the first argument and behind the second.\param d1 a double value to which the current x-coordinate must be compared\param d2 a double value to which the current x-coordinate must be compared\return true when the current x-coordinate is in between the two givenvalues; false otherwise */bool VecPosition::IsBetweenX( const double &d1, const double &d2 ){	return ( ( IsRightOf( d1 ) && IsLeftOf( d2 ) ) ? true : false );}/*! This method determines whether the current VecPosition is in between twogiven VecPositions when looking in the y-direction, i.e. whether the currentVecPosition is to the right of the first argument and to the left of thesecond.\param p1 a VecPosition to which the current VecPosition must be compared\param p2 a VecPosition to which the current VecPosition must be compared\return true when the current VecPosition is in between the two givenVecPositions when looking in the y-direction; false otherwise */bool VecPosition::IsBetweenY( const VecPosition &p1, const VecPosition &p2 ){	return ( ( IsTopOf( p1 ) && IsButtomOf( p2 ) ) ? true : false );}/*! This method determines whether the y-coordinate of the current VecPositionis in between two given double values, i.e. whether the y-coordinate of thecurrent VecPosition is to the right of the first argument and to the leftof the second.\param d1 a double value to which the current y-coordinate must be compared\param d2 a double value to which the current y-coordinate must be compared\return true when the current y-coordinate is in between the two givenvalues; false otherwise */bool VecPosition::IsBetweenY( const double &d1, const double &d2 ){	return ( ( IsTopOf( d1 ) && IsButtomOf( d2 ) ) ? true : false );}/*! This method Normalizes a VecPosition by Setting the magnitude of thecorresponding vector to 1. This thus changes the VecPosition itself.\return the result of normalizing the current VecPosition thus yielding adifferent VecPosition */VecPosition VecPosition::Normalize( ){	return ( SetMagnitude( 1.0 ) );}/*! This method Rotates the vector corresponding to the current VecPosition overa given angle thereby changing the current VecPosition itself. This is doneby calculating the polar coordinates of the current VecPosition and addingthe given angle to the phi-coordinate in the polar representation. The polarcoordinates are then converted back to Cartesian coordinates to obtain thedesired result.\param angle an angle in degrees over which the vector corresponding to thecurrent VecPosition must be Rotated\return the result of rotating the vector corresponding to the currentVecPosition over the given angle thus yielding a different VecPosition */VecPosition VecPosition::Rotate( AngRad angle ){	// determine the polar representation of the current VecPosition	double dMag    = this->GetMagnitude( );	double dNewDir = this->GetDirection( ) + angle;  // add rotation angle to phi	SetVecPosition( dMag, dNewDir, POLAR );          // convert back to Cartesian	return ( *this );}/*! This method converts the coordinates of the current VecPosition (which arerepresented in an global coordinate system with the origin at (0,0)) intorelative coordinates in a different coordinate system (e.g. relative to aplayer). The new coordinate system is defined by the arguments to themethod. The relative coordinates are now obtained by aligning the relativecoordinate system with the global coordinate system using a translation toMake both origins coincide followed by a rotation to align the axes.\param origin the origin of the relative coordinate frame\param ang the angle between the world frame and the relative frame(reasoning from the world frame)\return the result of converting the current global VecPosition into arelative VecPosition */VecPosition VecPosition::GlobalToRelative( VecPosition origin, AngRad ang ){	// convert global coordinates into relative coordinates by aligning relative	// frame and world frame. First perform translation to Make origins of both	// frames coincide. Then perform rotation to Make axes of both frames coincide	// (use negative angle since you Rotate relative frame to world frame).	*this -= origin;	return ( Rotate( -ang ) );}/*! This method converts the coordinates of the current VecPosition (which arerepresented in a relative coordinate system) into global coordinates inthe world frame (with origin at (0,0)). The relative coordinate system isdefined by the arguments to the method. The global coordinates are nowobtained by aligning the world frame with the relative frame using arotation to align the axes followed by a translation to Make both originscoincide.\param origin the origin of the relative coordinate frame\param ang the angle between the world frame and the relative frame(reasoning from the world frame)\return the result of converting the current relative VecPosition into anglobal VecPosition */VecPosition VecPosition::RelativeToGlobal( VecPosition origin, AngRad ang ){	// convert relative coordinates into global coordinates by aligning world	// frame and relative frame. First perform rotation to Make axes of both	// frames coincide (use positive angle since you Rotate world frame to	// relative frame). Then perform translation to Make origins of both frames	// coincide.	Rotate( ang );	*this += origin;	return ( *this );}/*! This method returns a VecPosition that lies somewhere on the vector betweenthe current VecPosition and a given VecPosition. The desired position isspecified by a given fraction of this vector (e.g. 0.5 means exactly inthe middle of the vector). The current VecPosition itself is left unchanged.\param p a VecPosition which defines the vector to the current VecPosition\param dFrac double representing the fraction of the connecting vector atwhich the desired VecPosition lies.\return the VecPosition which lies at fraction dFrac on the vectorconnecting p and the current VecPosition */VecPosition VecPosition::GetVecPositionOnLineFraction( VecPosition &p,double      dFrac ){	// determine point on line that lies at fraction dFrac of whole line	// example: this --- 0.25 ---------  p	// formula: this + dFrac * ( p - this ) = this - dFrac * this + dFrac * p =

⌨️ 快捷键说明

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