File indexing completed on 2025-01-18 09:54:41
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <cmath>
0011
0012 namespace CLHEP {
0013
0014 inline double Hep2Vector::x() const {
0015 return dx;
0016 }
0017
0018 inline double Hep2Vector::y() const {
0019 return dy;
0020 }
0021
0022 inline Hep2Vector::Hep2Vector(double x1, double y1)
0023 : dx(x1), dy(y1) {}
0024
0025 inline Hep2Vector::Hep2Vector( const Hep3Vector & v3)
0026 : dx(v3.x()), dy(v3.y()) {}
0027
0028 inline void Hep2Vector::setX(double x1) {
0029 dx = x1;
0030 }
0031
0032 inline void Hep2Vector::setY(double y1) {
0033 dy = y1;
0034 }
0035
0036 inline void Hep2Vector::set(double x1, double y1) {
0037 dx = x1;
0038 dy = y1;
0039 }
0040
0041 double & Hep2Vector::operator[] (int i) { return operator()(i); }
0042 double Hep2Vector::operator[] (int i) const { return operator()(i); }
0043
0044 inline Hep2Vector::Hep2Vector(const Hep2Vector & p)
0045 : dx(p.x()), dy(p.y()) {}
0046
0047 inline Hep2Vector::~Hep2Vector() {}
0048
0049 inline Hep2Vector & Hep2Vector::operator = (const Hep2Vector & p) {
0050 dx = p.x();
0051 dy = p.y();
0052 return *this;
0053 }
0054
0055 inline bool Hep2Vector::operator == (const Hep2Vector& v) const {
0056 return (v.x()==x() && v.y()==y()) ? true : false;
0057 }
0058
0059 inline bool Hep2Vector::operator != (const Hep2Vector& v) const {
0060 return (v.x()!=x() || v.y()!=y()) ? true : false;
0061 }
0062
0063 inline Hep2Vector& Hep2Vector::operator += (const Hep2Vector & p) {
0064 dx += p.x();
0065 dy += p.y();
0066 return *this;
0067 }
0068
0069 inline Hep2Vector& Hep2Vector::operator -= (const Hep2Vector & p) {
0070 dx -= p.x();
0071 dy -= p.y();
0072 return *this;
0073 }
0074
0075 inline Hep2Vector Hep2Vector::operator - () const {
0076 return Hep2Vector(-dx, -dy);
0077 }
0078
0079 inline Hep2Vector& Hep2Vector::operator *= (double a) {
0080 dx *= a;
0081 dy *= a;
0082 return *this;
0083 }
0084
0085 inline double Hep2Vector::dot(const Hep2Vector & p) const {
0086 return dx*p.x() + dy*p.y();
0087 }
0088
0089 inline double Hep2Vector::mag2() const {
0090 return dx*dx + dy*dy;
0091 }
0092
0093 inline double Hep2Vector::mag() const {
0094 return std::sqrt(mag2());
0095 }
0096
0097 inline double Hep2Vector::r() const {
0098 return std::sqrt(mag2());
0099 }
0100
0101 inline Hep2Vector Hep2Vector::unit() const {
0102 double tot = mag2();
0103 Hep2Vector p(*this);
0104 return tot > 0.0 ? p *= (1.0/std::sqrt(tot)) : Hep2Vector(1,0);
0105 }
0106
0107 inline Hep2Vector Hep2Vector::orthogonal() const {
0108 double x1 = std::fabs(dx), y1 = std::fabs(dy);
0109 if (x1 < y1) {
0110 return Hep2Vector(dy,-dx);
0111 }else{
0112 return Hep2Vector(-dy,dx);
0113 }
0114 }
0115
0116 inline double Hep2Vector::phi() const {
0117 return dx == 0.0 && dy == 0.0 ? 0.0 : std::atan2(dy,dx);
0118 }
0119
0120 inline double Hep2Vector::angle(const Hep2Vector & q) const {
0121 double ptot2 = mag2()*q.mag2();
0122 return ptot2 <= 0.0 ? 0.0 : std::acos(dot(q)/std::sqrt(ptot2));
0123 }
0124
0125 inline void Hep2Vector::setMag(double r1){
0126 double ph = phi();
0127 setX( r1 * std::cos(ph) );
0128 setY( r1 * std::sin(ph) );
0129 }
0130
0131 inline void Hep2Vector::setR(double r1){
0132 setMag(r1);
0133 }
0134
0135 inline void Hep2Vector::setPhi(double phi1){
0136 double ma = mag();
0137 setX( ma * std::cos(phi1) );
0138 setY( ma * std::sin(phi1) );
0139 }
0140
0141 inline void Hep2Vector::setPolar(double r1, double phi1){
0142 setX( r1 * std::cos(phi1) );
0143 setY( r1 * std::sin(phi1) );
0144 }
0145
0146 inline Hep2Vector operator + (const Hep2Vector & a, const Hep2Vector & b) {
0147 return Hep2Vector(a.x() + b.x(), a.y() + b.y());
0148 }
0149
0150 inline Hep2Vector operator - (const Hep2Vector & a, const Hep2Vector & b) {
0151 return Hep2Vector(a.x() - b.x(), a.y() - b.y());
0152 }
0153
0154 inline Hep2Vector operator * (const Hep2Vector & p, double a) {
0155 return Hep2Vector(a*p.x(), a*p.y());
0156 }
0157
0158 inline Hep2Vector operator * (double a, const Hep2Vector & p) {
0159 return Hep2Vector(a*p.x(), a*p.y());
0160 }
0161
0162 inline double operator * (const Hep2Vector & a, const Hep2Vector & b) {
0163 return a.dot(b);
0164 }
0165
0166 inline double Hep2Vector::getTolerance () {
0167 return tolerance;
0168 }
0169
0170 }
0171