📄 geometryr.h
字号:
/*Copyright (c) 2000-2002, Jelle Kok, University of AmsterdamAll rights reserved.Redistribution and use in source and binary forms, with or withoutmodification, are permitted provided that the following conditions are met:1. Redistributions of source code must retain the above copyright notice, thislist of conditions and the following disclaimer.2. Redistributions in binary form must reproduce the above copyright notice,this list of conditions and the following disclaimer in the documentationand/or other materials provided with the distribution.3. Neither the name of the University of Amsterdam nor the names of itscontributors may be used to endorse or promote products derived from thissoftware without specific prior written permission.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THEIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AREDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLEFOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIALDAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS ORSERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVERCAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USEOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*//*! \file Geometry.h<pre><b>File:</b> Geometry.h<b>Project:</b> Robocup Soccer Simulation Team: UvA Trilearn<b>Authors:</b> Jelle Kok<b>Created:</b> 12/02/2001<b>Last Revision:</b> $ID$<b>Contents:</b> Header file for the classes VecPosition, Geometry, Line,Circle and Rectangle. All the memberdata and member method declarations for all these classes can befound in this file toGether with some auxiliary functions fornumeric and goniometric purposes.<hr size=2><h2><b>Changes</b></h2><b>Date</b> <b>Author</b> <b>Comment</b>12/02/2001 Jelle Kok Initial version created09/06/2001 Remco de Boer Version including full documentation completed</pre>*/#ifndef _GEOMETRY_#define _GEOMETRY_#include <stdio.h>#include <stdlib.h>
#include <math.h>
#include "Globe.h"
typedef double AngRad; /*!< Type definition for angles in degrees. */typedef double AngDeg; /*!< Type definition for angles in radians. */#define INF 10000000#define EPS 0.000001 /*!< Value used for floating point equality tests. */const double UnknownDoubleValue = -1000.0; /*!< indicates unknown double */const int UnknownIntValue = -1000; /*!< indicates unknown int */const int UnknownTime = -20; /*!< indicates unknown time */const long UnknownMessageNr = -30; /*!< indicates unknown message nr*/#define M_PI 3.1415926 /* Value of pi */
class Maths{ public: // auxiliary numeric functions for determining the // maximum and minimum of two given double values and the Maths::Sign of a value static double Max ( double d1, double d2 ); static double Min ( double d1, double d2 ); static int Sign ( double d1 ); static double Limit ( double d, double dMin, double dMax);
// auxiliary goniometric functions which enable you to // specify angles in degrees rather than in radians static AngDeg Rad2Deg ( AngRad x ); static AngRad Deg2Rad ( AngDeg x ); static double cosDeg ( AngDeg x ); static double sinDeg ( AngDeg x ); static double tanDeg ( AngDeg x ); static AngDeg atanDeg ( double x ); static double atan2Deg( double x, double y ); static AngDeg acosDeg ( double x ); static AngDeg asinDeg ( double x ); #ifdef WIN32 /*! This function shall return the integral value (represented as a double) nearest x in the direction of the current rounding mode. The current rounding mode is implementation-defined. If the current rounding mode rounds toward negative infinity, then Maths::rint() shall be equivalent to floor() . If the current rounding mode rounds toward positive infinity, then Maths::rint() shall be equivalent to ceil(). url: http://www.opengroup.org/onlinepubs/007904975/functions/Maths::rint.html */ static double rint(double x) { return floor(x); } /*! The Maths::drand48() function shall return non-negative, double-precision, floating-point values, uniformly distributed over the interval [0.0,1.0). url: http://www.opengroup.org/onlinepubs/007904975/functions/Maths::drand48.html */ static double drand48() { return ((double)(rand() % 100)) / 100; } #endif};// various goniometric functionsbool IsAngInInterval ( AngRad ang, AngRad angMin, AngRad angMax );AngRad GetBisectorTwoAngles( AngRad angMin, AngRad angMax );/*! CoordSystem is an enumeration of the different specified coordinate systems.The two possibilities are CARTESIAN or POLAR. These values are for instanceused in the initializing a VecPosition. The CoordSystem indicates whetherthe supplied arguments represent the position in cartesian or in polarcoordinates. */enum CoordSystemT{ CARTESIAN, POLAR};/******************************************************************************//******************** CLASS VECPOSITION ***********************************//******************************************************************************//*! This class contains an x- and y-coordinate of a position (x,y) as memberdata and methods which operate on this position. The standard arithmeticoperators are overloaded and can thus be applied to positions (x,y). It isalso possible to represent a position in polar coordinates (r,phi), sincethe class contains a method to convert these into cartesian coordinates(x,y). */class VecPosition{ // private member data private: double m_x; /*!< x-coordinate of this position */ double m_y; /*!< y-coordinate of this position */ // public methods public: // constructor for VecPosition class VecPosition ( double vx = 0, double vy = 0, CoordSystemT cs = CARTESIAN); // overloaded arithmetic operators dbPOINT GetdbPOINT(); VecPosition operator - ( ); VecPosition operator + ( const double &d ); VecPosition operator + ( const VecPosition &p ); VecPosition operator - ( const double &d ); VecPosition operator - ( const VecPosition &p ); VecPosition operator * ( const double &d ); VecPosition operator * ( const VecPosition &p ); VecPosition operator / ( const double &d ); VecPosition operator / ( const VecPosition &p ); void operator = ( const double &d ); void operator += ( const VecPosition &p ); void operator += ( const double &d ); void operator -= ( const VecPosition &p ); void operator -= ( const double &d ); void operator *= ( const VecPosition &p ); void operator *= ( const double &d ); void operator /= ( const VecPosition &p ); void operator /= ( const double &d ); bool operator != ( const VecPosition &p ); bool operator != ( const double &d ); bool operator == ( const VecPosition &p ); bool operator == ( const double &d ); // methods for producing output void Show ( CoordSystemT cs = CARTESIAN); void Print( FILE* file ); void ToString ( char buf[], CoordSystemT cs = CARTESIAN); // Set- and Get methods for private member variables bool SetX ( double dX ); double GetX ( ) const; bool SetY ( double dY ); double GetY ( ) const;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -