// SpacePoint.h #ifndef SpacePoint_H #define SpacePoint_H // Describes a space point. The default Space point is at the origin. // Derived classes can be used to set values in cartesian, cylindrical // or spherical coordinates. Point is set in the constructor and // cannot be changed. The methods simply return different coordinates. // // Transformations (translations, rotations, etc) are carried out by // external functions which return new SpacePoints. #include #ifdef DEFECT_NO_BOOL #include #endif class SpacePoint { protected: // data double _x; double _y; double _z; double _xy; double _xyz; double _phi; double _tht; public: // static methods // Return if two doubles are close enough to be considered equal. // This is used to compare components for operator==. static bool equal(double x1, double x2); // Return the tolerance used in equal. static double equal_tolerance(); public: // methods // Default constructor. // Sets point to be the origin. SpacePoint( ); // Destructor. virtual ~SpacePoint( ); // Cartesian x. double x( ) const { return _x; }; // Cartesian y. double y( ) const { return _y; }; // Cartesian z. double z( ) const { return _z; }; // Cylindrical r. double rxy( ) const { return _xy; }; // Cylindrical phi. double phi( ) const { return _phi; }; // Spherical r. double rxyz( ) const { return _xyz; }; // Spherical theta. double theta( ) const { return _tht; }; // cos(phi) double cos_phi( ) const; // sin(phi) double sin_phi( ) const; // cos(phi) double sin_theta( ) const; // cos(phi) double cos_theta( ) const; }; std::ostream& operator<<(std::ostream & stream, const SpacePoint& spt); //********************************************************************** class CartesianPoint : public SpacePoint { public: // Constructor. CartesianPoint(double x, double y, double z); }; //********************************************************************** class CylindricalPoint : public SpacePoint { public: // Constructor. CylindricalPoint(double r, double phi, double z); }; //********************************************************************** class SphericalPoint : public SpacePoint { public: // Constructor. SphericalPoint(double r, double phi, double theta); }; //********************************************************************** // Free functions. //********************************************************************** // Equality. bool operator==(const SpacePoint& lhs, const SpacePoint& rhs); //********************************************************************** // Inequality. bool operator!=(const SpacePoint& lhs, const SpacePoint& rhs); //********************************************************************** // Return the distance between two space points. double distance(const SpacePoint spt1, const SpacePoint spt2); //********************************************************************** #endif