// SpacePointVector.h #ifndef SpacePointVector_H #define SpacePointVector_H // Describes a vector at a point in space. The vector can be constructed // in Cartesian, cylindrical or spherical coordinates and components can // fetched for any of these systems. The default constructor creates // a vector of zero length at the origin. Finite vectors of nonzero length // at any point can be constructed using subclasses. // // The point and vector stored in a space vector cannot be modified except // by assignment from another space vector. // // Transformations (translations, rotations, etc) are not provided. // It is expected these will be carried out by external functions which // return new SpacePointVector objects. // // The three orthogonal coordinate systems are defined in the usual way: // Cartesian: (x, y, z) // Cylindrical: (rxy, phi, z) // Spherical: (rxyz, theta, phi) . #include "SpacePoint.h" class SpacePointVector : public SpacePoint { protected: // data // The vector. double _vx; double _vy; double _vz; public: // methods // Default constructor. SpacePointVector(); // Constructor from a space point. // Creates a vector of zero length. SpacePointVector(const SpacePoint& spt); // Copy constructor. SpacePointVector(const SpacePointVector& rhs); // Destructor. virtual ~SpacePointVector(); // Assignment operator SpacePointVector& operator=(const SpacePointVector& rhs); // Cartesian x. double v_x() const { return _vx; }; // Cartesian y. double v_y() const { return _vy; }; // Cartesian or cylindrical z. double v_z() const { return _vz; }; // Cylndrical rxy component. double v_rxy() const; // Cylndrical or spherical phi component. // Return 0 if vx = vy = 0. double v_phi() const; // Spherical rxyz component. double v_rxyz() const; // Spherical theta component. double v_theta() const; // Return the magnitude of the vector. double magnitude() const; }; //********************************************************************** // Free functions. //********************************************************************** // Equality. bool operator==(const SpacePointVector& lhs, const SpacePointVector& rhs); //********************************************************************** // Inequality. bool operator!=(const SpacePointVector& lhs, const SpacePointVector& rhs); //********************************************************************** // Output stream. std::ostream& operator<<(std::ostream & stream, const SpacePointVector& svec); //********************************************************************** // Subclasses //********************************************************************** class CartesianPointVector : public SpacePointVector { public: // Constructor from coordinates and direction. CartesianPointVector(double x, double y, double z, double vx, double vy, double vz); // Constructor from space point and direction. CartesianPointVector(const SpacePoint& spt, double vx, double vy, double vz); }; //********************************************************************** class CylindricalPointVector : public SpacePointVector { public: // Constructor from coordinates and direction. CylindricalPointVector(double r, double phi, double z, double vr, double vphi, double vz); // Constructor from space point and direction. CylindricalPointVector(const SpacePoint& spt, double vr, double vphi, double vz); }; //********************************************************************** class SphericalPointVector : public SpacePointVector { public: // Constructor from coordinates and direction. // Arguments are (dr/ds, r*dtheta/ds, r*sin(theta)*dphi/ds). SphericalPointVector(double r, double theta, double phi, double vr, double vtheta, double vphi); // Constructor from space point and direction. SphericalPointVector(const SpacePoint& spt, double vr, double vtheta, double vphi); }; //********************************************************************** #endif