// Functions for three-vector class // Glen Cowan, RHUL Physics Dept., 4 December 2001. #include #include #include "ThreeVector.h" ThreeVector::ThreeVector(){ xVal = 0.; yVal = 0.; zVal = 0.; } ThreeVector::ThreeVector (float x, float y, float z){ xVal = x; yVal = y; zVal = z; } float ThreeVector::x(){ return xVal; } float ThreeVector::y(){ return yVal; } float ThreeVector::z(){ return zVal; } void ThreeVector::set(float x, float y, float z){ xVal = x; yVal = y; zVal = z; } float ThreeVector::r(){ float r2 = pow(xVal,2) + pow(yVal,2) + pow(zVal,2); float rVal = sqrt(r2); return rVal; } float ThreeVector::cosTheta(){ float cosThetaVal = this->z()/this->r(); return cosThetaVal; } float ThreeVector::theta(){ float thetaVal = acos ( this->cosTheta() ); return thetaVal; } float ThreeVector::rho(){ float rhoVal = sqrt ( this->x()*this->x() + this->y()*this->y() ); return rhoVal; } float ThreeVector::cosPhi(){ float cosPhiVal = this->x() / this->rho() ; return cosPhiVal; } float ThreeVector::sinPhi(){ float sinPhiVal = this->y() / this->rho() ; return sinPhiVal; } float ThreeVector::phi(){ float phiVal; const float pi = 3.14159265; if ( this->y() >=0 ) { phiVal = acos ( this->cosPhi() ); } else { phiVal = acos ( - this->cosPhi() ) + pi ; } return phiVal; } float dotProd (ThreeVector a, ThreeVector b){ float dot = a.x()*b.x() + a.y()*b.y() + a.z()*b.z(); return dot; }