19 #ifndef ROOT_Math_GenVector_Polar2D
20 #define ROOT_Math_GenVector_Polar2D 1
52 Polar2D() : fR(1.), fPhi(0) { }
57 Polar2D(T r,T phi) : fR(r), fPhi(phi) { Restrict(); }
63 template <
class CoordSystem >
64 explicit Polar2D(
const CoordSystem & v ) :
65 fR(v.R() ), fPhi(v.Phi() ) { Restrict(); }
73 Polar2D(
const Polar2D & v) :
74 fR(v.R() ), fPhi(v.Phi() ) { }
79 Polar2D & operator= (
const Polar2D & v) {
89 void SetCoordinates(Scalar r, Scalar phi)
90 { fR=r; fPhi=phi; Restrict(); }
95 void GetCoordinates(Scalar& r, Scalar& phi)
const {r=fR; phi=fPhi;}
98 Scalar R()
const {
return fR;}
99 Scalar Phi()
const {
return fPhi; }
100 Scalar X()
const {
return fR * cos(fPhi); }
101 Scalar Y()
const {
return fR * sin(fPhi); }
102 Scalar Mag2()
const {
return fR*fR;}
111 void SetR(
const T & r) {
119 void SetPhi(
const T & phi) {
127 void SetXY(Scalar a, Scalar b);
131 inline static double pi() {
return M_PI; }
136 inline void Restrict() {
137 if (fPhi <= -pi() || fPhi > pi()) fPhi = fPhi - floor(fPhi / (2 * pi()) + .5) * 2 * pi();
158 fPhi = ( fPhi > 0 ? fPhi - pi() : fPhi + pi() );
164 void Rotate(T angle) {
173 template <
class CoordSystem >
174 Polar2D & operator= (
const CoordSystem & c ) {
183 bool operator==(
const Polar2D & rhs)
const {
184 return fR == rhs.fR && fPhi == rhs.fPhi;
186 bool operator!= (
const Polar2D & rhs)
const {
return !(operator==(rhs));}
193 T x()
const {
return X();}
194 T y()
const {
return Y();}
200 #if defined(__MAKECINT__) || defined(G__DICTIONARY)
225 #if defined(__MAKECINT__) || defined(G__DICTIONARY)
234 void Polar2D<T>::SetXY(Scalar a, Scalar b) {
235 *
this = Cartesian2D<Scalar>(a, b);
239 #if defined(__MAKECINT__) || defined(G__DICTIONARY)
245 void Polar2D<T>::SetX(Scalar a) {
246 GenVector_exception e(
"Polar2D::SetX() is not supposed to be called");
248 Cartesian2D<Scalar> v(*
this); v.SetX(a); *
this = Polar2D<Scalar>(v);
251 void Polar2D<T>::SetY(Scalar a) {
252 GenVector_exception e(
"Polar2D::SetY() is not supposed to be called");
254 Cartesian2D<Scalar> v(*
this); v.SetY(a); *
this = Polar2D<Scalar>(v);