qupid 0.2
Quasi-Signal Generation Model for Pixelized Detector
Loading...
Searching...
No Matches
QPVector.cpp
1#include "QPVector.hpp"
2#include "QPMath.hpp"
3
4#include <cmath>
5
6#include <iostream>
7#include <string>
8#include <sstream>
9
10QPVector::QPVector(): fX(0), fY(0), fZ(0){}
11QPVector::QPVector(double x, double y): fX(x), fY(y), fZ(0){}
12QPVector::QPVector(double x, double y, double z): fX(x), fY(y), fZ(z){}
13QPVector::QPVector(const QPVector& other): fX(other.fX), fY(other.fY), fZ(other.fZ){;}
14
15//Get
16double QPVector::X(){return fX;}
17double QPVector::Y(){return fY;}
18double QPVector::Z(){return fZ;}
19void QPVector::Get(double& x, double& y, double& z){x = fX; y = fY; z=fZ;}
20
22 double norm = Norm();
23 return QPVector(fX/norm, fY/norm, fZ/norm);
24}
25
26//Operator, returning result
27
28QPVector QPVector::Scale(double& number){
29 // return QPVector(number*fX, number*fY, number*fZ);
30 return QPVector(number*fX, number*fY, number*fZ);
31}
32
34 return sqrt(fX*fX + fY*fY + fZ*fZ);
35}
36
38 return fX*fX + fY*fY + fZ*fZ;
39}
40
41//Operator, Self Closed operation
42void QPVector::AddThis(const QPVector& other){
43 // fX += other.fX;
44 // fY += other.fY;
45 // fZ += other.fZ;
46 (*this)+=other;
47}
49 // fX -= other.fX;
50 // fY -= other.fY;
51 // fZ -= other.fZ;
52 (*this)-=other;
53}
54void QPVector::CrossThis(const QPVector& other){
55 (*this)^=other;
56}
57
58void QPVector::ScaleThis(const double& number){
59 (*this).operator*=(number);
60}
61
62//Operator, Coveniences
63
64// double QPVector::operator*(const QPVector& other){
65// return sqrt(fX*other.fX + fY*other.fY + fZ*other.fZ);
66// }
67
68// QPVector& QPVector::operator*(const double& other){
69// return * new QPVector(fX*other, fY*other, fZ*other);
70// }
71
72// QPVector& QPVector::operator^(const QPVector& other){
73// double x = fY*other.fZ-fY*other.fZ;
74// double y = fZ*other.fX-fX*other.fZ;
75// double z = fX*other.fY-fY*other.fX;
76// return * new QPVector(x,y,z);
77// }
78
79double QPVector::GetAngle(QPVector other){ //Get Angle [0, Pi]
80 return acos(Unit().Dot(other.Unit()));
81}
82
84 return GetAngle(other)*180/QPMath::Pi;
85}
86
87std::string QPVector::Print(bool quite){
88 std::ostringstream anss;
89
90 anss << "[" << fX << "," << fY << "," << fZ << "]";
91
92 std::string ans = anss.str();
93 if(!quite){
94 // std::cout<<fX<<"\t"<<fY<<"\t"<<fZ<<std::endl;
95 std::cout<<"[x,y,z] = " << ans << std::endl;
96 }
97
98 return ans;
99}
100
101// QPVector operator+ ( QPVector& a, QPVector& b) {
102// return QPVector(a.fX+b.fX, a.fY+b.fY, a.fZ+b.fZ);
103// }
104
105QPVector operator+ ( QPVector a, QPVector b) {
106 return QPVector(a.fX+b.fX, a.fY+b.fY, a.fZ+b.fZ);
107}
108
109// QPVector operator- ( QPVector& a, QPVector& b) {
110// return QPVector(a.fX-b.fX, a.fY-b.fY, a.fZ-b.fZ);
111// }
112
113QPVector operator- ( QPVector a, QPVector b) {
114 return QPVector(a.fX-b.fX, a.fY-b.fY, a.fZ-b.fZ);
115}
116
117// QPVector operator^ ( QPVector& a, QPVector& b) {
118// double x = a.fY*b.fZ-a.fY*b.fZ;
119// double y = a.fZ*b.fX-a.fX*b.fZ;
120// double z = a.fX*b.fY-a.fY*b.fX;
121// return QPVector(x,y,z);
122// }
123
124QPVector operator^ ( QPVector a, QPVector b) {
125 double x = a.fY*b.fZ-a.fZ*b.fY;
126 double y = a.fZ*b.fX-a.fX*b.fZ;
127 double z = a.fX*b.fY-a.fY*b.fX;
128 return QPVector(x,y,z);
129}
130
131// QPVector operator* ( QPVector &vec, double other) {
132// return QPVector(other*vec.fX, other*vec.fY, other*vec.fZ);
133// }
134
135QPVector operator* ( QPVector vec, double other) {
136 return QPVector(other*vec.fX, other*vec.fY, other*vec.fZ);
137}
138
139// double operator* ( QPVector& other, QPVector& vec) {
140// return vec.Dot(other);
141// }
142
143// QPVector operator* (double other, QPVector &vec) {
144// return QPVector(other*vec.fX, other*vec.fY, other*vec.fZ);
145// }
146
147QPVector operator* (double other, QPVector vec) {
148 return QPVector(other*vec.fX, other*vec.fY, other*vec.fZ);
149}
150
151double operator* ( QPVector other, QPVector vec) {
152 return vec.Dot(other);
153}
3-component double vector with hand-rolled operations.
Definition QPVector.hpp:13
void AddThis(const QPVector &other)
In-place add; delegates to operator+= and inherits its z-component defect (see operator+=).
Definition QPVector.cpp:42
void CrossThis(const QPVector &other)
In-place cross product; delegates to operator^= and inherits its overwrite defect (see operator^=).
Definition QPVector.cpp:54
void ScaleThis(const double &number)
Multiply all components in place.
Definition QPVector.cpp:58
double Dot(QPVector other) const
Dot product .
Definition QPVector.hpp:248
double Z()
Definition QPVector.cpp:18
QPVector Scale(double &number)
Scaled copy .
Definition QPVector.cpp:28
QPVector Unit()
Unit vector .
Definition QPVector.cpp:21
QPVector()
Zero vector.
Definition QPVector.cpp:10
double Y()
Definition QPVector.cpp:17
double GetAngle(QPVector other)
Angle between this vector and other, .
Definition QPVector.cpp:79
double X()
Definition QPVector.cpp:16
std::string Print(bool quite=false)
Formats the vector as "[x,y,z]".
Definition QPVector.cpp:87
double Norm2()
Definition QPVector.cpp:37
double Norm()
Definition QPVector.cpp:33
void SubstractThis(const QPVector &other)
In-place subtract; delegates to operator-= and inherits its z-component defect (see operator-=).
Definition QPVector.cpp:48
double GetAngleDegree(QPVector other)
GetAngle converted to degrees.
Definition QPVector.cpp:83
void Get(double &x, double &y, double &z)
Writes the components into the given references.
Definition QPVector.cpp:19
const double Pi
Definition QPMath.hpp:16