// sv-7.cc // A ZOOM PhysicsVectors tutorial example // // Tutorial example 6 for the SpaceVector and UnitVector class: // // Cylindrical Coordinates // // * Constructing vectors in Cylindrical Coordinates // * Modifying Cylindrical Components of a Vector // Key lines are marked by // <------------- // Get the SpaceVector class #include "ZMutility/ZMenvironment.h" #include "ZMutility/FixedTypes.h" #include "PhysicsVectors/SpaceVector.h" #include "PhysicsVectors/UnitVector.h" ZM_USING_NAMESPACE( zmpv ) USING( std::cout ) USING( std::endl ) // These classes themselves pull in FixedTypes, but just to // remind ourselves that we are using Float8, not double, for // 64-bit floats... #include "ZMutility/FixedTypes.h" ZM_USING_NAMESPACE( zmfxt ) // This example will use iostream output, so get that -- // in a portable way. #include "ZMutility/iostream" using std::cout; using std::endl; int main() { // ***** Constructing vectors in Cylindrical Coordinates // Here is how to construct a vector by supplying rho, phi, z //----------------------------------------------------------- Float8 rho = 3; Float8 phi = 30; Float8 z = 4; SpaceVector v ( rho, phi, DEGREES, z ); // <------------- cout << "v = " << v << endl; // Here is how to access cylindrical coordinates of a vector //---------------------------------------------------------- Float8 a = v.rho(); // <------------- Float8 b = v.phi(); // <------------- Float8 c = v.z(); // <------------- // Note that phi() and z() have the same meaning // as phi() in spherical coordinates and z in // Cartesian coordinates. cout << "rho = " << v.rho() << " perp = " << v.perp() << endl; cout << "r = " << v.r() << " mag = " << v.mag() << endl; cout << "phi = " << v.phi() << " angle = " << (v.perpPart()).angle(X_HAT) << endl; // ***** Rotating around a coordinate axis // ***** Modifying Cylindrical Components of a Vector // Here is how to modify theta while keeping rho and phi fixed //------------------------------------------------------------ v.set (2, 3, 4); cout << " rho = " << v.rho() << " r = " << v.r() << " phi = " << v.phi() << " z = " << v.z() << " theta = " << v.theta() << endl; v.setCylTheta ( .4 ); // <------------- cout << " rho = " << v.rho() << " r = " << v.r() << " phi = " << v.phi() << " z = " << v.z() << " theta = " << v.theta() << endl; // The usual v.theta() = whatever keeps spherical r and phi fixed v.setTheta( .5 ); cout << " rho = " << v.rho() << " r = " << v.r() << " phi = " << v.phi() << " z = " << v.z() << " theta = " << v.theta() << endl; // Here is how to modify eta while keeping rho and phi fixed //---------------------------------------------------------- v.setCylEta ( .4 ); // <------------- cout << " rho = " << v.rho() << " r = " << v.r() << " phi = " << v.phi() << " z = " << v.z() << " eta = " << v.eta() << endl; return 0; } /* end of main */