?? geometry.h
字號:
#ifndef _GEOMETRY_#define _GEOMETRY_#include <math.h> // needed for M_PI constant#include <string> // needed for string#include <iostream>#include "Logger.h"using namespace std;typedef double AngRad; /*!< Type definition for angles in degrees. */typedef double AngDeg; /*!< Type definition for angles in radians. */#define EPSILON 0.0001 /*!< Value used for floating point equality tests. */// auxiliary numeric functions for determining the// maximum and minimum of two given double values and the sign of a valuedouble max ( double d1, double d2 );double min ( double d1, double d2 );int sign ( double d1 );// auxiliary goniometric functions which enable you to// specify angles in degrees rather than in radiansAngDeg Rad2Deg ( AngRad x );AngRad Deg2Rad ( AngDeg x );double cosDeg ( AngDeg x );double sinDeg ( AngDeg x );double tanDeg ( AngDeg x );AngDeg atanDeg ( double x );double atan2Deg( double x, double y );AngDeg acosDeg ( double x );AngDeg asinDeg ( double x );// various goniometric functionsbool isAngInInterval ( AngDeg ang, AngDeg angMin, AngDeg angMax );AngDeg getBisectorTwoAngles( AngDeg angMin, AngDeg angMax );/*! CoordSystem is an enumeration of the different specified coordinate systems. The two possibilities are CARTESIAN or POLAR. These values are for instance used in the initializing a VecPosition. The CoordSystem indicates whether the supplied arguments represent the position in cartesian or in polar coordinates. */enum CoordSystemT { CARTESIAN, POLAR};/*****************************************************************************//******************** CLASS VECPOSITION **********************************//*****************************************************************************//*! This class contains an x- and y-coordinate of a position (x,y) as member data and methods which operate on this position. The standard arithmetic operators are overloaded and can thus be applied to positions (x,y). It is also possible to represent a position in polar coordinates (r,phi), since the class contains a method to convert these into cartesian coordinates (x,y). */class VecPosition{ // private member dataprivate: double m_x; /*!< x-coordinate of this position */ double m_y; /*!< y-coordinate of this position */ double m_z; /*!< z-coordinate of this position */ // public methodspublic: // constructor for VecPosition class VecPosition ( double vx = 0, double vy = 0, double vz = 0, CoordSystemT cs =CARTESIAN); // overloaded arithmetic operators 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 friend ostream& operator << ( ostream &os, VecPosition v ); void show ( CoordSystemT cs =CARTESIAN); string str ( 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; bool setZ ( double dZ ); double getZ ( ) const; // set- and get methods for derived position information void setVecPosition ( double dX = 0, double dY = 0, double dZ = 0, CoordSystemT cs =CARTESIAN); double getDistanceTo ( const VecPosition p ); VecPosition setMagnitude ( double d ); double getMagnitude ( ) const; AngDeg getDirection ( ) const; AngDeg getTheta ( ) const; AngDeg getPhi ( ) const; //cross product VecPosition cross ( const VecPosition p ); // comparison methods for positions bool isInFrontOf ( const VecPosition &p ); bool isInFrontOf ( const double &d ); bool isBehindOf ( const VecPosition &p ); bool isBehindOf ( const double &d ); bool isLeftOf ( const VecPosition &p ); bool isLeftOf ( const double &d ); bool isRightOf ( const VecPosition &p ); bool isRightOf ( const double &d ); bool isUpOf ( const VecPosition &p ); bool isUpOf ( const double &d ); bool isDownOf ( const VecPosition &p ); bool isDownOf ( 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 ); bool isBetweenZ ( const VecPosition &p1, const VecPosition &p2 ); bool isBetweenZ ( const double &d1, const double &d2 ); // conversion methods for positions VecPosition normalize ( ); VecPosition rotate ( AngDeg angle ); VecPosition globalToRelative ( VecPosition orig, AngDeg ang ); VecPosition relativeToGlobal ( VecPosition orig, AngDeg ang ); VecPosition getVecPositionOnLineFraction( VecPosition &p, double dFrac ); // static class methods static VecPosition getVecPositionFromPolar( double dMag, AngDeg theta, AngDeg phi ); static AngDeg normalizeAngle ( AngDeg angle );};/*! This is for using a shared position as an unknown position */const VecPosition UnknownPosition = VecPosition(-1000.0,-1000.0,-1000.0);/*****************************************************************************//********************* CLASS GEOMETRY ************************************//*****************************************************************************/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -