Polar.cxx
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "Polar.hxx"
00024 #include <iostream>
00025 #include <sstream>
00026
00027 namespace CLAM
00028 {
00029
00030 const Polar& Polar::operator += (const Polar& a)
00031 {
00032 TData r1 = fabs(a.mMag) * CLAM_cos(a.mAng);
00033 TData i1 = fabs(a.mMag) * CLAM_sin(a.mAng);
00034 TData r2 = fabs(mMag) * CLAM_cos(mAng);
00035 TData i2 = fabs(mMag) * CLAM_sin(mAng);
00036
00037 TData r3 = r1+r2;
00038 TData i3 = i1+i2;
00039
00040 mMag = sqrt (r3*r3 + i3*i3);
00041 mAng = atan2 (i3,r3);
00042
00043 return *this;
00044 }
00045
00046
00047 const Polar& Polar::operator -= (const Polar& a)
00048 {
00049 TData r1 = fabs(a.mMag) * CLAM_cos(a.mAng);
00050 TData i1 = fabs(a.mMag) * CLAM_sin(a.mAng);
00051 TData r2 = fabs(mMag) * CLAM_cos(mAng);
00052 TData i2 = fabs(mMag) * CLAM_sin(mAng);
00053
00054 TData r3 = r2-r1;
00055 TData i3 = i2-i1;
00056
00057 mMag = CLAM_sqrt (r3*r3 + i3*i3);
00058 mAng = CLAM_atan2 (i3,r3);
00059
00060 return *this;
00061 }
00062
00063
00064 Polar Polar::operator + (const Polar& b) const
00065 {
00066 TData r1 = fabs(mMag) * CLAM_cos(mAng);
00067 TData i1 = fabs(mMag) * CLAM_sin(mAng);
00068 TData r2 = fabs(b.mMag) * CLAM_cos(b.mAng);
00069 TData i2 = fabs(b.mMag) * CLAM_sin(b.mAng);
00070
00071 TData r3 = r1+r2;
00072 TData i3 = i1+i2;
00073
00074 Polar ret(CLAM_sqrt (r3*r3 + i3*i3),CLAM_atan2 (i3,r3));
00075 return ret;
00076 }
00077
00078
00079 Polar Polar::operator - (const Polar& b) const
00080 {
00081 TData r1 = fabs(mMag) * CLAM_cos(mAng);
00082 TData i1 = fabs(mMag) * CLAM_sin(mAng);
00083 TData r2 = fabs(b.mMag) * CLAM_cos(b.mAng);
00084 TData i2 = fabs(b.mMag) * CLAM_sin(b.mAng);
00085
00086 TData r3 = r1-r2;
00087 TData i3 = i1-i2;
00088
00089 Polar ret(CLAM_sqrt (r3*r3 + i3*i3),CLAM_atan2 (i3,r3));
00090 return ret;
00091 }
00092
00093 std::istream& operator >> (std::istream & is,
00094 Polar & a)
00095 {
00096 if (is.flags() & std::ios::skipws) {
00097 char c = '\0';
00098 do
00099 is.get(c);
00100 while (is && isspace(c));
00101 if (is) is.putback(c);
00102 }
00103 char c = '\0';
00104 is >> c;
00105 if (c!='{') {
00106 if (is) is.putback(c);
00107
00108 return is;
00109 }
00110 TData m;
00111 TData p;
00112 if (!(is >> m)) return is;
00113 if (!(is >> p)) return is;
00114 if (is.flags() & std::ios::skipws) {
00115 char c = '\0';
00116 do
00117 is.get(c);
00118 while (is && isspace(c));
00119 if (is) is.putback(c);
00120 }
00121 if (!is.get(c) || c!='}') return is;
00122
00123 a.SetMag(m);
00124 a.SetAng(p);
00125 return is;
00126 }
00127
00128 std::ostream& operator << (std::ostream& myStream, const Polar& a)
00129 {
00130 return myStream
00131 << "{"
00132 << a.Mag()
00133 << " "
00134 << a.Ang()
00135 << "}";
00136 }
00137
00138 }
00139
00140