📄 geometryr.h
字号:
// Set- and Get methods for derived position information
void SetVecPosition ( double dX = 0,
double dY = 0,
CoordSystemT cs = CARTESIAN);
double GetDistanceTo ( const VecPosition p );
VecPosition SetMagnitude ( double d );
double GetMagnitude ( ) const;
AngRad GetDirection ( ) const;
// comparison methods for positions
bool IsRightOf ( const VecPosition &p );
bool IsRightOf ( const double &d );
bool IsLeftOf ( const VecPosition &p );
bool IsLeftOf ( const double &d );
bool IsButtomOf ( const VecPosition &p );
bool IsButtomOf ( const double &d );
bool IsTopOf ( const VecPosition &p );
bool IsTopOf ( const double &d );
bool IsBetweenX ( const VecPosition &p1,
const VecPosition &p2 );
bool IsBetweenX ( const double &d1,
const double &d2 );
bool IsBetweenY ( const VecPosition &p1,
const VecPosition &p2 );
bool IsBetweenY ( const double &d1,
const double &d2 );
// conversion methods for positions
VecPosition Normalize ( );
VecPosition Rotate ( AngRad angle );
VecPosition GlobalToRelative ( VecPosition orig,
AngRad ang );
VecPosition RelativeToGlobal ( VecPosition orig,
AngRad ang );
VecPosition GetVecPositionOnLineFraction( VecPosition &p,
double dFrac );
// static class methods
static VecPosition GetVecPositionFromPolar( double dMag,
AngRad ang );
static AngRad NormalizeAngle ( AngRad angle );
static AngRad NormalizeAngle2PI ( AngRad angle );
};
/******************************************************************************/
/********************* CLASS GEOMETRY *************************************/
/******************************************************************************/
/*! This class contains several static methods dealing with geometry.*/
class Geometry
{
public:
// geometric series
static double GetLengthGeomSeries(double dFirst,double dRatio,double dSum );
static double GetSumGeomSeries (double dFirst,double dRatio,double dLength);
static double GetSumInfGeomSeries(double dFirst,double dRatio );
static double GetFirstGeomSeries (double dSum, double dRatio,double dLength);
static double GetFirstInfGeomSeries(double dSum,double dRatio );
// abc formula
static int AbcFormula(double a,double b, double c, double *s1, double *s2);
};
/******************************************************************************/
/********************** CLASS CIRCLE ******************************************/
/******************************************************************************/
/*!This class represents a circle. A circle is defined by one VecPosition
(which denotes the center) and its radius. */
class Circle
{
VecPosition m_posCenter; /*!< Center of the circle */
double m_dRadius; /*!< Radius of the circle */
public:
Circle( );
Circle( VecPosition pos, double dR );
// Get and Set methods
bool SetCircle ( VecPosition pos,
double dR );
bool SetRadius ( double dR );
double GetRadius ( );
bool SetCenter ( VecPosition pos );
VecPosition GetCenter ( );
double GetCircumference ( );
double GetArea ( );
// Calculate intersection points and area with other circle
bool IsInside ( VecPosition pos );
int GetIntersectionPoints ( Circle c,
VecPosition *p1,
VecPosition *p2 );
double GetIntersectionArea ( Circle c );
} ;
/******************************************************************************/
/*********************** CLASS LINE *******************************************/
/******************************************************************************/
/*!This class contains the representation of a line. A line is defined
by the formula ay + bx + c = 0. The coefficients a, b and c are stored
and used in the calculations. */
class Line
{
public:
// a line is defined by the formula: ay + bx + c = 0
double m_a; /*!< This is the a coefficient in the line ay + bx + c = 0 */
double m_b; /*!< This is the b coefficient in the line ay + bx + c = 0 */
double m_c; /*!< This is the c coefficient in the line ay + bx + c = 0 */
public:
VecPosition GetPointInLine(VecPosition pos1, double dDistance);
Line( double a, double b, double c );
Line();
void SetLine(double a, double b, double c) { m_a = a; m_b = b; m_c = c; };
// Get intersection points with this line
VecPosition GetIntersection ( Line line );
int GetCircleIntersectionPoints( Circle circle,
VecPosition *posSolution1,
VecPosition *posSolution2 );
Line GetPerpendicularLine ( VecPosition pos );
VecPosition GetPointOnLineClosestTo ( VecPosition pos );
double GetDistanceWithPoint ( VecPosition pos );
bool IsInBetween ( VecPosition pos,
VecPosition point1,
VecPosition point2 );
// Calculate associated variables in the line
double GetYGivenX ( double x );
double GetXGivenY ( double y );
double GetACoefficient ( ) const;
double GetBCoefficient ( ) const;
double GetCCoefficient ( ) const;
double GetSlope() const { return -m_b/m_a; };
// static methods to Make a line using an easier representation.
static Line MakeLineFromTwoPoints ( VecPosition pos1,
VecPosition pos2 );
static Line MakeLineFromPositionAndAngle( VecPosition vec,
AngRad angle );
};
/******************************************************************************/
/********************** CLASS RECTANGLE ***************************************/
/******************************************************************************/
/*!This class represents a rectangle. A rectangle is defined by two VecPositions
the one at the upper left corner and the one at the right bottom. */
class Rect
{
VecPosition m_posLeftTop; /*!< top left position of the rectangle */
VecPosition m_posRightBottom; /*!< bottom right position of the rectangle */
public:
Rect ( VecPosition pos, VecPosition pos2 );
Rect () {};
// checks whether point lies inside the rectangle
bool IsInside ( VecPosition pos );
// standard Get and Set methosd
void SetRectanglePoints( VecPosition pos1,
VecPosition pos2 );
bool SetPosLeftTop ( VecPosition pos );
VecPosition GetPosLeftTop ( );
bool SetPosRightBottom ( VecPosition pos );
VecPosition GetPosRightBottom ( );
void SetLeft(double x) { m_posLeftTop.SetX(x) ; };
void SetTop(double y) { m_posLeftTop.SetY(y) ; };
void SetRight(double x) { m_posRightBottom.SetX(x) ; };
void SetBottom(double y) { m_posRightBottom.SetY(y) ; };
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -