CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
CLHEP::Hep2Vector Class Reference

#include <TwoVector.h>

Public Types

enum  { X =0 , Y =1 , NUM_COORDINATES =2 , SIZE =NUM_COORDINATES }
 

Public Member Functions

 Hep2Vector (double x=0.0, double y=0.0)
 
 Hep2Vector (const Hep2Vector &p)
 
 Hep2Vector (Hep2Vector &&p)=default
 
 Hep2Vector (const Hep3Vector &)
 
 ~Hep2Vector ()
 
double x () const
 
double y () const
 
double operator() (int i) const
 
double operator[] (int i) const
 
doubleoperator() (int i)
 
doubleoperator[] (int i)
 
void setX (double x)
 
void setY (double y)
 
void set (double x, double y)
 
double phi () const
 
double mag2 () const
 
double mag () const
 
double r () const
 
void setPhi (double phi)
 
void setMag (double r)
 
void setR (double r)
 
void setPolar (double r, double phi)
 
Hep2Vectoroperator= (const Hep2Vector &p)
 
Hep2Vectoroperator= (Hep2Vector &&p)=default
 
bool operator== (const Hep2Vector &v) const
 
bool operator!= (const Hep2Vector &v) const
 
int compare (const Hep2Vector &v) const
 
bool operator> (const Hep2Vector &v) const
 
bool operator< (const Hep2Vector &v) const
 
bool operator>= (const Hep2Vector &v) const
 
bool operator<= (const Hep2Vector &v) const
 
double howNear (const Hep2Vector &p) const
 
bool isNear (const Hep2Vector &p, double epsilon=tolerance) const
 
double howParallel (const Hep2Vector &p) const
 
bool isParallel (const Hep2Vector &p, double epsilon=tolerance) const
 
double howOrthogonal (const Hep2Vector &p) const
 
bool isOrthogonal (const Hep2Vector &p, double epsilon=tolerance) const
 
Hep2Vectoroperator+= (const Hep2Vector &p)
 
Hep2Vectoroperator-= (const Hep2Vector &p)
 
Hep2Vector operator- () const
 
Hep2Vectoroperator*= (double a)
 
Hep2Vector unit () const
 
Hep2Vector orthogonal () const
 
double dot (const Hep2Vector &p) const
 
double angle (const Hep2Vector &) const
 
void rotate (double)
 
 operator Hep3Vector () const
 

Static Public Member Functions

static double getTolerance ()
 
static double setTolerance (double tol)
 

Static Public Attributes

static const int ZMpvToleranceTicks = 100
 

Friends

std::ostream & operator<< (std::ostream &, const Hep2Vector &)
 
double operator* (const Hep2Vector &a, const Hep2Vector &b)
 
Hep2Vector operator* (const Hep2Vector &p, double a)
 
Hep2Vector operator* (double a, const Hep2Vector &p)
 
Hep2Vector operator/ (const Hep2Vector &p, double a)
 
Hep2Vector operator+ (const Hep2Vector &a, const Hep2Vector &b)
 
Hep2Vector operator- (const Hep2Vector &a, const Hep2Vector &b)
 

Detailed Description

Author

Definition at line 45 of file TwoVector.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
NUM_COORDINATES 
SIZE 

Definition at line 49 of file TwoVector.h.

Constructor & Destructor Documentation

◆ Hep2Vector() [1/4]

CLHEP::Hep2Vector::Hep2Vector ( double  x = 0.0,
double  y = 0.0 
)
inline

◆ Hep2Vector() [2/4]

CLHEP::Hep2Vector::Hep2Vector ( const Hep2Vector p)
inline

◆ Hep2Vector() [3/4]

CLHEP::Hep2Vector::Hep2Vector ( Hep2Vector &&  p)
inlinedefault

◆ Hep2Vector() [4/4]

CLHEP::Hep2Vector::Hep2Vector ( const Hep3Vector )
explicit

◆ ~Hep2Vector()

CLHEP::Hep2Vector::~Hep2Vector ( )
inline

Member Function Documentation

◆ angle()

double CLHEP::Hep2Vector::angle ( const Hep2Vector ) const
inline

◆ compare()

int CLHEP::Hep2Vector::compare ( const Hep2Vector v) const

Definition at line 89 of file TwoVector.cc.

89 {
90 if ( dy > v.dy ) {
91 return 1;
92 } else if ( dy < v.dy ) {
93 return -1;
94 } else if ( dx > v.dx ) {
95 return 1;
96 } else if ( dx < v.dx ) {
97 return -1;
98 } else {
99 return 0;
100 }
101} /* Compare */

Referenced by operator<(), operator<=(), operator>(), and operator>=().

◆ dot()

double CLHEP::Hep2Vector::dot ( const Hep2Vector p) const
inline

◆ getTolerance()

static double CLHEP::Hep2Vector::getTolerance ( )
inlinestatic

◆ howNear()

double CLHEP::Hep2Vector::howNear ( const Hep2Vector p) const

Definition at line 122 of file TwoVector.cc.

122 {
123 double d = (*this - p).mag2();
124 double pdp = dot(p);
125 if ( (pdp > 0) && (d < pdp) ) {
126 return std::sqrt (d/pdp);
127 } else if ( (pdp == 0) && (d == 0) ) {
128 return 0;
129 } else {
130 return 1;
131 }
132} /* howNear */
double mag2() const
double dot(const Hep2Vector &p) const

◆ howOrthogonal()

double CLHEP::Hep2Vector::howOrthogonal ( const Hep2Vector p) const

Definition at line 163 of file TwoVector.cc.

163 {
164 // | V1 dot V2 | / | V1 x V2 |
165 // Of course, the "cross product" is fictitious but the math is valid
166 double v1v2 = std::fabs(dot(v));
167 if ( v1v2 == 0 ) {
168 return 0; // Even if one or both are 0, they are considered orthogonal
169 }
170 double abscross = std::fabs ( dx * v.y() - dy - v.x() );
171 if ( v1v2 >= abscross ) {
172 return 1;
173 } else {
174 return v1v2/abscross;
175 }
176} /* howOrthogonal() */

◆ howParallel()

double CLHEP::Hep2Vector::howParallel ( const Hep2Vector p) const

Definition at line 134 of file TwoVector.cc.

134 {
135 // | V1 x V2 | / | V1 dot V2 |
136 // Of course, the "cross product" is fictitious but the math is valid
137 double v1v2 = std::fabs(dot(v));
138 if ( v1v2 == 0 ) {
139 // Zero is parallel to no other vector except for zero.
140 return ( (mag2() == 0) && (v.mag2() == 0) ) ? 0 : 1;
141 }
142 double abscross = std::fabs ( dx * v.y() - dy - v.x() );
143 if ( abscross >= v1v2 ) {
144 return 1;
145 } else {
146 return abscross/v1v2;
147 }
148} /* howParallel() */

◆ isNear()

bool CLHEP::Hep2Vector::isNear ( const Hep2Vector p,
double  epsilon = tolerance 
) const

Definition at line 117 of file TwoVector.cc.

117 {
118 double limit = dot(p)*epsilon*epsilon;
119 return ( (*this - p).mag2() <= limit );
120} /* isNear() */

◆ isOrthogonal()

bool CLHEP::Hep2Vector::isOrthogonal ( const Hep2Vector p,
double  epsilon = tolerance 
) const

Definition at line 178 of file TwoVector.cc.

179 {
180 // | V1 dot V2 | <= epsilon * | V1 x V2 |
181 // Of course, the "cross product" is fictitious but the math is valid
182 double v1v2 = std::fabs(dot(v));
183 double abscross = std::fabs ( dx * v.y() - dy - v.x() );
184 return ( v1v2 <= epsilon * abscross );
185} /* isOrthogonal() */

◆ isParallel()

bool CLHEP::Hep2Vector::isParallel ( const Hep2Vector p,
double  epsilon = tolerance 
) const

Definition at line 150 of file TwoVector.cc.

151 {
152 // | V1 x V2 | <= epsilon * | V1 dot V2 |
153 // Of course, the "cross product" is fictitious but the math is valid
154 double v1v2 = std::fabs(dot(v));
155 if ( v1v2 == 0 ) {
156 // Zero is parallel to no other vector except for zero.
157 return ( (mag2() == 0) && (v.mag2() == 0) );
158 }
159 double abscross = std::fabs ( dx * v.y() - dy - v.x() );
160 return ( abscross <= epsilon * v1v2 );
161} /* isParallel() */

◆ mag()

double CLHEP::Hep2Vector::mag ( ) const
inline

◆ mag2()

double CLHEP::Hep2Vector::mag2 ( ) const
inline

◆ operator Hep3Vector()

CLHEP::Hep2Vector::operator Hep3Vector ( ) const

Definition at line 85 of file TwoVector.cc.

85 {
86 return Hep3Vector ( dx, dy, 0.0 );
87}

◆ operator!=()

bool CLHEP::Hep2Vector::operator!= ( const Hep2Vector v) const
inline

◆ operator()() [1/2]

double & CLHEP::Hep2Vector::operator() ( int  i)

Definition at line 41 of file TwoVector.cc.

41 {
42 static double dummy;
43 switch(i) {
44 case X:
45 return dx;
46 case Y:
47 return dy;
48 default:
49 ZMthrowA (ZMxpvIndexRange(
50 "Hep2Vector::operator() : bad index"));
51 return dummy;
52 }
53}
#define ZMthrowA(A)
Definition: ZMxpv.h:128

◆ operator()() [2/2]

double CLHEP::Hep2Vector::operator() ( int  i) const

Definition at line 29 of file TwoVector.cc.

29 {
30 if (i == 0) {
31 return x();
32 }else if (i == 1) {
33 return y();
34 }else{
35 ZMthrowA(ZMxpvIndexRange(
36 "Hep2Vector::operator(): bad index"));
37 return 0.0;
38 }
39}
double x() const
double y() const

◆ operator*=()

Hep2Vector & CLHEP::Hep2Vector::operator*= ( double  a)
inline

◆ operator+=()

Hep2Vector & CLHEP::Hep2Vector::operator+= ( const Hep2Vector p)
inline

◆ operator-()

Hep2Vector CLHEP::Hep2Vector::operator- ( ) const
inline

◆ operator-=()

Hep2Vector & CLHEP::Hep2Vector::operator-= ( const Hep2Vector p)
inline

◆ operator<()

bool CLHEP::Hep2Vector::operator< ( const Hep2Vector v) const

Definition at line 107 of file TwoVector.cc.

107 {
108 return (compare(v) < 0);
109}
int compare(const Hep2Vector &v) const
Definition: TwoVector.cc:89

◆ operator<=()

bool CLHEP::Hep2Vector::operator<= ( const Hep2Vector v) const

Definition at line 113 of file TwoVector.cc.

113 {
114 return (compare(v) <= 0);
115}

◆ operator=() [1/2]

Hep2Vector & CLHEP::Hep2Vector::operator= ( const Hep2Vector p)
inline

◆ operator=() [2/2]

Hep2Vector & CLHEP::Hep2Vector::operator= ( Hep2Vector &&  p)
inlinedefault

◆ operator==()

bool CLHEP::Hep2Vector::operator== ( const Hep2Vector v) const
inline

◆ operator>()

bool CLHEP::Hep2Vector::operator> ( const Hep2Vector v) const

Definition at line 104 of file TwoVector.cc.

104 {
105 return (compare(v) > 0);
106}

◆ operator>=()

bool CLHEP::Hep2Vector::operator>= ( const Hep2Vector v) const

Definition at line 110 of file TwoVector.cc.

110 {
111 return (compare(v) >= 0);
112}

◆ operator[]() [1/2]

double & CLHEP::Hep2Vector::operator[] ( int  i)
inline

◆ operator[]() [2/2]

double CLHEP::Hep2Vector::operator[] ( int  i) const
inline

◆ orthogonal()

Hep2Vector CLHEP::Hep2Vector::orthogonal ( ) const
inline

◆ phi()

double CLHEP::Hep2Vector::phi ( ) const
inline

◆ r()

double CLHEP::Hep2Vector::r ( ) const
inline

◆ rotate()

void CLHEP::Hep2Vector::rotate ( double  angler)

Definition at line 55 of file TwoVector.cc.

55 {
56 double s1 = std::sin(angler);
57 double c = std::cos(angler);
58 double xx = dx;
59 dx = c*xx - s1*dy;
60 dy = s1*xx + c*dy;
61}

◆ set()

void CLHEP::Hep2Vector::set ( double  x,
double  y 
)
inline

Referenced by CLHEP::operator>>().

◆ setMag()

void CLHEP::Hep2Vector::setMag ( double  r)
inline

◆ setPhi()

void CLHEP::Hep2Vector::setPhi ( double  phi)
inline

◆ setPolar()

void CLHEP::Hep2Vector::setPolar ( double  r,
double  phi 
)
inline

◆ setR()

void CLHEP::Hep2Vector::setR ( double  r)
inline

◆ setTolerance()

double CLHEP::Hep2Vector::setTolerance ( double  tol)
static

Definition at line 22 of file TwoVector.cc.

22 {
23// Set the tolerance for Hep2Vectors to be considered near one another
24 double oldTolerance (tolerance);
25 tolerance = tol;
26 return oldTolerance;
27}

◆ setX()

void CLHEP::Hep2Vector::setX ( double  x)
inline

◆ setY()

void CLHEP::Hep2Vector::setY ( double  y)
inline

◆ unit()

Hep2Vector CLHEP::Hep2Vector::unit ( ) const
inline

◆ x()

double CLHEP::Hep2Vector::x ( ) const
inline

◆ y()

double CLHEP::Hep2Vector::y ( ) const
inline

Friends And Related Function Documentation

◆ operator* [1/3]

double operator* ( const Hep2Vector a,
const Hep2Vector b 
)
friend

◆ operator* [2/3]

Hep2Vector operator* ( const Hep2Vector p,
double  a 
)
friend

◆ operator* [3/3]

Hep2Vector operator* ( double  a,
const Hep2Vector p 
)
friend

◆ operator+

Hep2Vector operator+ ( const Hep2Vector a,
const Hep2Vector b 
)
friend

◆ operator-

Hep2Vector operator- ( const Hep2Vector a,
const Hep2Vector b 
)
friend

◆ operator/

Hep2Vector operator/ ( const Hep2Vector p,
double  a 
)
friend

Definition at line 63 of file TwoVector.cc.

63 {
64 if (a==0) {
65 ZMthrowA(ZMxpvInfiniteVector( "Division of Hep2Vector by zero"));
66 }
67 return Hep2Vector(p.x()/a, p.y()/a);
68}
Hep2Vector(double x=0.0, double y=0.0)

◆ operator<<

std::ostream & operator<< ( std::ostream &  ,
const Hep2Vector  
)
friend

Definition at line 70 of file TwoVector.cc.

70 {
71 os << "(" << q.x() << ", " << q.y() << ")";
72 return os;
73}

Member Data Documentation

◆ ZMpvToleranceTicks

const int CLHEP::Hep2Vector::ZMpvToleranceTicks = 100
static

Definition at line 194 of file TwoVector.h.


The documentation for this class was generated from the following files: