qupid 0.2
Quasi-Signal Generation Model for Pixelized Detector
Loading...
Searching...
No Matches
QPVector Class Reference

3-component double vector with hand-rolled operations. More...

#include <QPVector.hpp>

Public Member Functions

 QPVector ()
 Zero vector.
 
 QPVector (double x, double y)
 2D point; z is set to 0.
 
 QPVector (double x, double y, double z)
 
 QPVector (const QPVector &other)
 Copy constructor.
 
double X ()
 
double Y ()
 
double Z ()
 
void Get (double &x, double &y, double &z)
 Writes the components into the given references.
 
QPVector Unit ()
 Unit vector $ \vec{v}/|\vec{v}| $.
 
double Dot (QPVector other) const
 Dot product $ a_x b_x + a_y b_y + a_z b_z $.
 
QPVector Cross (QPVector other) const
 Cross product $ \vec{a}\times\vec{b} $ (correct, unlike operator^=).
 
QPVector Scale (double &number)
 Scaled copy $ (kx, ky, kz) $.
 
double Norm ()
 
double Norm2 ()
 
void AddThis (const QPVector &other)
 In-place add; delegates to operator+= and inherits its z-component defect (see operator+=).
 
void SubstractThis (const QPVector &other)
 In-place subtract; delegates to operator-= and inherits its z-component defect (see operator-=).
 
void CrossThis (const QPVector &other)
 In-place cross product; delegates to operator^= and inherits its overwrite defect (see operator^=).
 
void ScaleThis (const double &number)
 Multiply all components in place.
 
QPVector & operator= (const QPVector &other)
 Component-wise copy assignment.
 
QPVector & operator+= (const QPVector &other)
 In-place add.
 
QPVector & operator-= (const QPVector &other)
 In-place subtract.
 
QPVector & operator*= (const double &other)
 Multiply all components in place.
 
QPVector & operator^= (const QPVector &other)
 In-place cross product.
 
double & operator() (const int &i)
 Reference to component i (0 = x, 1 = y, 2 = z).
 
double & operator[] (const int &i)
 Reference to component i (0 = x, 1 = y, 2 = z); same behavior and warning as operator().
 
double GetAngle (QPVector other)
 Angle between this vector and other, $ \arccos(\hat{a}\cdot\hat{b}) \in [0,\pi] $.
 
double GetAngleDegree (QPVector other)
 GetAngle converted to degrees.
 
std::string Print (bool quite=false)
 Formats the vector as "[x,y,z]".
 

Friends

QPVector operator+ (QPVector &a, QPVector &b)
 Component-wise sum (lvalue overload).
 
QPVector operator+ (QPVector a, QPVector b)
 Component-wise sum.
 
QPVector operator- (QPVector a, QPVector b)
 Component-wise difference.
 
QPVector operator^ (QPVector a, QPVector b)
 Cross product $ \vec{a}\times\vec{b} $.
 
QPVector operator* (QPVector vec, double other)
 Scaled copy.
 
QPVector operator* (double other, QPVector vec)
 Scaled copy.
 
double operator* (QPVector other, QPVector vec)
 Dot product.
 

Detailed Description

3-component double vector with hand-rolled operations.

The 2-argument constructor sets z = 0, so the same type serves the 2D signal geometry.

Warning
The compound operators += , -= and ^= do not compute what their symbols suggest — see the individual warnings below. The binary friends and Dot()/Cross() are correct.

Definition at line 13 of file QPVector.hpp.

Constructor & Destructor Documentation

◆ QPVector() [1/4]

QPVector::QPVector ( )

Zero vector.

Definition at line 10 of file QPVector.cpp.

Referenced by Cross(), Scale(), and Unit().

◆ QPVector() [2/4]

QPVector::QPVector ( double  x,
double  y 
)

2D point; z is set to 0.

Parameters
xcomponent x
ycomponent y

Definition at line 11 of file QPVector.cpp.

◆ QPVector() [3/4]

QPVector::QPVector ( double  x,
double  y,
double  z 
)
Parameters
xcomponent x
ycomponent y
zcomponent z

Definition at line 12 of file QPVector.cpp.

◆ QPVector() [4/4]

QPVector::QPVector ( const QPVector &  other)

Copy constructor.

Parameters
othersource vector

Definition at line 13 of file QPVector.cpp.

Member Function Documentation

◆ X()

double QPVector::X ( )
Returns
component x

Definition at line 16 of file QPVector.cpp.

◆ Y()

double QPVector::Y ( )
Returns
component y

Definition at line 17 of file QPVector.cpp.

◆ Z()

double QPVector::Z ( )
Returns
component z

Definition at line 18 of file QPVector.cpp.

◆ Get()

void QPVector::Get ( double &  x,
double &  y,
double &  z 
)

Writes the components into the given references.

Parameters
xreceives component x
yreceives component y
zreceives component z

Definition at line 19 of file QPVector.cpp.

◆ Unit()

QPVector QPVector::Unit ( )

Unit vector $ \vec{v}/|\vec{v}| $.

No zero-norm guard: a zero vector yields NaN components.

Returns
normalized copy

Definition at line 21 of file QPVector.cpp.

References Norm(), and QPVector().

Referenced by GetAngle().

◆ Dot()

double QPVector::Dot ( QPVector  other) const
inline

Dot product $ a_x b_x + a_y b_y + a_z b_z $.

Parameters
othersecond operand
Returns
scalar product

Definition at line 248 of file QPVector.hpp.

Referenced by GetAngle().

◆ Cross()

QPVector QPVector::Cross ( QPVector  other) const
inline

Cross product $ \vec{a}\times\vec{b} $ (correct, unlike operator^=).

Parameters
othersecond operand
Returns
cross product vector

Definition at line 252 of file QPVector.hpp.

References QPVector().

◆ Scale()

QPVector QPVector::Scale ( double &  number)

Scaled copy $ (kx, ky, kz) $.

Parameters
numberscale factor k (historical non-const reference)
Returns
scaled copy

Definition at line 28 of file QPVector.cpp.

References QPVector().

◆ Norm()

double QPVector::Norm ( )
Returns
Euclidean norm $ \sqrt{x^2+y^2+z^2} $

Definition at line 33 of file QPVector.cpp.

Referenced by Unit().

◆ Norm2()

double QPVector::Norm2 ( )
Returns
squared norm $ x^2+y^2+z^2 $

Definition at line 37 of file QPVector.cpp.

◆ AddThis()

void QPVector::AddThis ( const QPVector &  other)

In-place add; delegates to operator+= and inherits its z-component defect (see operator+=).

Parameters
othervector to add

Definition at line 42 of file QPVector.cpp.

◆ SubstractThis()

void QPVector::SubstractThis ( const QPVector &  other)

In-place subtract; delegates to operator-= and inherits its z-component defect (see operator-=).

Parameters
othervector to subtract

Definition at line 48 of file QPVector.cpp.

◆ CrossThis()

void QPVector::CrossThis ( const QPVector &  other)

In-place cross product; delegates to operator^= and inherits its overwrite defect (see operator^=).

Parameters
othersecond operand

Definition at line 54 of file QPVector.cpp.

◆ ScaleThis()

void QPVector::ScaleThis ( const double &  number)

Multiply all components in place.

Parameters
numberscale factor

Definition at line 58 of file QPVector.cpp.

◆ operator=()

QPVector & QPVector::operator= ( const QPVector &  other)
inline

Component-wise copy assignment.

Parameters
othersource vector
Returns
this vector

Definition at line 200 of file QPVector.hpp.

◆ operator+=()

QPVector & QPVector::operator+= ( const QPVector &  other)
inline

In-place add.

Warning
The z component receives the other vector's x component (fZ += other.fX); x and y are handled correctly. Only safe when both z components and other.fX are zero.
Parameters
othervector to add
Returns
this vector

Definition at line 207 of file QPVector.hpp.

◆ operator-=()

QPVector & QPVector::operator-= ( const QPVector &  other)
inline

In-place subtract.

Warning
Same defect as operator+=: the z component has the other vector's x component subtracted (fZ -= other.fX).
Parameters
othervector to subtract
Returns
this vector

Definition at line 214 of file QPVector.hpp.

◆ operator*=()

QPVector & QPVector::operator*= ( const double &  other)
inline

Multiply all components in place.

Parameters
otherscale factor
Returns
this vector

Definition at line 221 of file QPVector.hpp.

◆ operator^=()

QPVector & QPVector::operator^= ( const QPVector &  other)
inline

In-place cross product.

Warning
Does not compute a cross product: the x component is zeroed by a duplicated term, and the y and z formulas then read components that were already overwritten during the update. Use Cross() or the binary operator^ instead.
Parameters
othersecond operand
Returns
this vector

Definition at line 228 of file QPVector.hpp.

◆ operator()()

double & QPVector::operator() ( const int &  i)
inline

Reference to component i (0 = x, 1 = y, 2 = z).

Warning
i > 2 only prints a message and still reads past the local lookup table; negative i is never checked. Both are undefined behavior.
Parameters
icomponent index
Returns
reference to the component

Definition at line 235 of file QPVector.hpp.

◆ operator[]()

double & QPVector::operator[] ( const int &  i)
inline

Reference to component i (0 = x, 1 = y, 2 = z); same behavior and warning as operator().

Parameters
icomponent index
Returns
reference to the component

Definition at line 241 of file QPVector.hpp.

◆ GetAngle()

double QPVector::GetAngle ( QPVector  other)

Angle between this vector and other, $ \arccos(\hat{a}\cdot\hat{b}) \in [0,\pi] $.

Parameters
othersecond vector
Returns
angle in radians

Definition at line 79 of file QPVector.cpp.

References Dot(), and Unit().

Referenced by GetAngleDegree().

◆ GetAngleDegree()

double QPVector::GetAngleDegree ( QPVector  other)

GetAngle converted to degrees.

Parameters
othersecond vector
Returns
angle in degrees

Definition at line 83 of file QPVector.cpp.

References GetAngle(), and QPMath::Pi.

◆ Print()

std::string QPVector::Print ( bool  quite = false)

Formats the vector as "[x,y,z]".

Parameters
quitewhen true, only returns the string; when false, also prints it to stdout
Returns
the formatted string

Definition at line 87 of file QPVector.cpp.

Friends And Related Symbol Documentation

◆ operator+ [1/2]

QPVector operator+ ( QPVector &  a,
QPVector &  b 
)
friend

Component-wise sum (lvalue overload).

Warning
Declared but never defined (the definition is commented out in QPVector.cpp): overload resolution prefers it for two lvalue operands and the program then fails to link. Pass at least one rvalue, or use AddThis/the by-value overload.
Parameters
afirst operand
bsecond operand
Returns
component-wise sum

◆ operator+ [2/2]

QPVector operator+ ( QPVector  a,
QPVector  b 
)
friend

Component-wise sum.

Parameters
afirst operand
bsecond operand
Returns
component-wise sum

Definition at line 105 of file QPVector.cpp.

◆ operator-

QPVector operator- ( QPVector  a,
QPVector  b 
)
friend

Component-wise difference.

Parameters
afirst operand
bsecond operand
Returns
component-wise difference a - b

Definition at line 113 of file QPVector.cpp.

◆ operator^

QPVector operator^ ( QPVector  a,
QPVector  b 
)
friend

Cross product $ \vec{a}\times\vec{b} $.

Parameters
afirst operand
bsecond operand
Returns
cross product vector

Definition at line 124 of file QPVector.cpp.

◆ operator* [1/3]

QPVector operator* ( QPVector  vec,
double  other 
)
friend

Scaled copy.

Parameters
vecvector operand
otherscale factor
Returns
scaled vector

Definition at line 135 of file QPVector.cpp.

◆ operator* [2/3]

QPVector operator* ( double  other,
QPVector  vec 
)
friend

Scaled copy.

Parameters
otherscale factor
vecvector operand
Returns
scaled vector

Definition at line 147 of file QPVector.cpp.

◆ operator* [3/3]

double operator* ( QPVector  other,
QPVector  vec 
)
friend

Dot product.

Parameters
otherfirst operand
vecsecond operand
Returns
scalar product

Definition at line 151 of file QPVector.cpp.


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