/* University College London Dept of Physics Course in C++ 3C59 | all rights reserved 2000 | | Utility: IMPLEMENTATION of the ThreeVector class | | | Author: P.Clarke */ #include #include #include"../util/ThreeVector.h" //............. // initialise void ThreeVector::initialise( float qx, float qy, float qz ) { px = qx ; py = qy ; pz = qz ; } //................................. // To obtain the magnitude squared float ThreeVector::magnitudesq( ) { return ( px*px + py*py + pz*pz ) ; } //......................... // To obtain the magnitude float ThreeVector::magnitude( ) { return sqrt( magnitudesq( ) ); } //......................................... // To obtain the phin angle in the x-y plane float ThreeVector::phi( ) { return acos( px / sqrt(px*px + py*py) ) ; } //........................................ // To take a dot product of two 3 vectors float ThreeVector::dotProduct( ThreeVector t2 ) { return ( px*t2.px + py*t2.py + pz*t2.pz ) ; } //.................................................... // To obtain the angle between two vectors in radians float ThreeVector::angle( ThreeVector t2 ) { // Note: in this method we call other methods of this object itself // (the dotProduct and magnitude methods) as well as calling the magnitude method // of the argument. float angle ; angle = dotProduct( t2 ) / magnitude( ) / t2.magnitude( ) ; angle = acos(angle) ; return angle ; } //................................... // To dump out the contents to cout void ThreeVector::dump( ) { std::cout << " The vector contents are " << " px= " << px << " py= " << py << " pz= " << pz << std::endl ; } //............................................... // Default constructor ThreeVector::ThreeVector( ) { px = 0 ; py = 0 ; pz = 0 ; } //....................... // Constructor to set to some value ThreeVector::ThreeVector( float qx, float qy, float qz ) { px = qx ; py = qy ; pz = qz ; } //....................... // Constructor to set to specified magnitude, and define it to be in the x-y plane // with the given value of phi in radians. ThreeVector::ThreeVector( float mag, float phi ) { px = mag * cos( phi ) ; py = mag * sin( phi ) ; pz = 0. ; } //....................... // Copy Constructor ThreeVector::ThreeVector( ThreeVector& src ) { px = src.px ; py = src.py ; pz = src.pz ; }