Garfield++ v1r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
Heed::straight Class Reference

#include <straight.h>

+ Inheritance diagram for Heed::straight:

Public Member Functions

point Gpiv (void) const
 
vec Gdir (void) const
 
 straight ()
 
 straight (const point &fpiv, const vec &fdir)
 
straightoperator= (const straight &fsl)
 
 straight (const point &fp1, const point &fp2)
 
 straight (const plane pl1, const plane pl2)
 
 straight (const point *pt, int qpt, int anum)
 
 straight (const straight sl[4], point pt[2], vfloat prec)
 
int check_point_in (const point &fp, vfloat prec) const
 
point cross (const straight &sl, vfloat prec) const
 
vfloat vecdistance (const straight &sl, int &type_of_cross, point pt[2]) const
 
vfloat distance (const straight &sl, int &type_of_cross, point pt[2]) const
 
vfloat distance (const point &fpt) const
 
vfloat distance (const point &fpt, point &fcpt) const
 
point vecdistance (const vec normal, const straight &slt)
 
 straight (straight *sl, int qsl, const straight &sl_start, int anum, vfloat precision, vfloat *dist, point(*pt)[2], vfloat &mean2dist)
 
- Public Member Functions inherited from absref
virtual ~absref ()
 
virtual void down (const abssyscoor *fasc)
 
virtual void up (const abssyscoor *fasc)
 
virtual void turn (const vec &dir, vfloat angle)
 
virtual void shift (const vec &dir)
 

Protected Member Functions

virtual void get_components (ActivePtr< absref_transmit > &aref_tran)
 

Protected Attributes

point piv
 
vec dir
 

Static Protected Attributes

static absrefabsref::*[2] aref
 

Friends

int operator== (const straight &sl1, const straight &sl2)
 
int operator!= (const straight &sl1, const straight &sl2)
 
int apeq (const straight &sl1, const straight &sl2, vfloat prec)
 
int not_apeq (const straight &sl1, const straight &sl2, vfloat prec)
 
std::ostream & operator<< (std::ostream &file, const straight &s)
 

Detailed Description

Definition at line 25 of file straight.h.

Constructor & Destructor Documentation

◆ straight() [1/7]

Heed::straight::straight ( )
inline

Definition at line 40 of file straight.h.

40: piv(), dir() {}

Referenced by straight().

◆ straight() [2/7]

Heed::straight::straight ( const point fpiv,
const vec fdir 
)
inline

Definition at line 41 of file straight.h.

42 : piv(fpiv), dir(unit_vec(fdir)) {
43 }

◆ straight() [3/7]

Heed::straight::straight ( const point fp1,
const point fp2 
)
inline

Definition at line 49 of file straight.h.

49 : piv(fp1), dir() {
50 pvecerror("straight::straight(const point& fp1, const point& fp2)");
51 check_econd12(fp1, ==, fp2, mcerr);
52 dir = unit_vec(fp2 - fp1);
53 }
#define check_econd12(a, sign, b, stream)
Definition: FunNameStack.h:380
#define mcerr
Definition: prstream.h:135
#define pvecerror(string)
Definition: vec.h:52

◆ straight() [4/7]

Heed::straight::straight ( const plane  pl1,
const plane  pl2 
)

Definition at line 27 of file straight.cpp.

27 {
28 pvecerror("straight::straight(const plane pl1, const plane pl2)");
29 *this = pl1.cross(pl2);
30}

◆ straight() [5/7]

Heed::straight::straight ( const point pt,
int  qpt,
int  anum 
)

Definition at line 219 of file straight.cpp.

220 {
221 pvecerror("straight::straight(const point* pt, int qpt, int anum) ");
222 check_econd11(qpt, < 2, mcerr);
223 check_econd21(anum, < 0 ||, >= 3, mcerr);
224
225 if (qpt == 2) {
226 *this = straight(pt[0], pt[1]);
227 return;
228 }
229 double* x = new double[qpt];
230 double* y = new double[qpt];
231 double* z = new double[qpt];
232 int n;
233 for (n = 0; n < qpt; n++) {
234 x[n] = pt[n].v.x;
235 y[n] = pt[n].v.y;
236 z[n] = pt[n].v.z;
237 }
238 point piv1;
239 if (anum == 0) {
240 linexi2 lcy(qpt, x, y);
241 linexi2 lcz(qpt, x, z);
242 piv = point(lcy.x_mean, lcy.line(lcy.x_mean), lcz.line(lcy.x_mean));
243 piv1 = point(lcy.x_mean + 1, lcy.line(lcy.x_mean + 1),
244 lcz.line(lcy.x_mean + 1));
245 } else if (anum == 1) {
246 linexi2 lcx(qpt, y, x);
247 linexi2 lcz(qpt, y, z);
248 piv = point(lcx.line(lcx.x_mean), lcx.x_mean, lcz.line(lcx.x_mean));
249 // lcx.x_mean = lcz.x_mean
250 piv1 = point(lcx.line(lcx.x_mean + 1), lcx.x_mean + 1,
251 lcz.line(lcx.x_mean + 1));
252 } else {
253 linexi2 lcx(qpt, z, x);
254 linexi2 lcy(qpt, z, y);
255 piv = point(lcx.line(lcx.x_mean), lcy.line(lcx.x_mean), lcx.x_mean);
256 piv1 = point(lcx.line(lcx.x_mean + 1), lcy.line(lcx.x_mean + 1),
257 lcx.x_mean + 1);
258 }
259 dir = unit_vec(piv1 - piv);
260
261 delete x;
262 delete y;
263 delete z;
264}
#define check_econd21(a, sign1_b1_sign0, sign2_b2, stream)
Definition: FunNameStack.h:428
#define check_econd11(a, signb, stream)
Definition: FunNameStack.h:366
Definition: vec.h:477
vec v
Definition: vec.h:479
vfloat y
Definition: vec.h:250
vfloat x
Definition: vec.h:250
vfloat z
Definition: vec.h:250

◆ straight() [6/7]

Heed::straight::straight ( const straight  sl[4],
point  pt[2],
vfloat  prec 
)

Definition at line 266 of file straight.cpp.

266 {
267 pvecerror("straight::straight(const straight sl[4], point pt[2], vfloat "
268 "precision)");
269 int i;
270 vfloat meandist;
271 point ptprev[2];
272 point ptcurr[2];
273 ptprev[0] = pt[0];
274 ptprev[1] = pt[1];
275 ptcurr[0] = pt[0];
276 ptcurr[1] = pt[1];
277 do {
278 meandist = 0;
279 for (i = 0; i < 2; i++) {
280 int is; // index of line to make plane
281 int ip; // index of point to make plane
282 int isc; // index of line to find point
283 if (i == 0) {
284 is = 0;
285 ip = 1;
286 isc = 1;
287 } else {
288 is = 3;
289 ip = 0;
290 isc = 2;
291 }
292 plane pn(sl[is], ptcurr[ip]);
293 ptcurr[i] = pn.cross(sl[isc]);
294 meandist += length2(ptcurr[i] - ptprev[i]);
295 mcout << " i=" << i << " ptprev[i]=" << ptprev[i]
296 << " ptcurr[i]=" << ptcurr[i] << '\n';
297 ptprev[i] = ptcurr[i];
298 }
299 meandist /= 2.0;
300 meandist = sqrt(meandist);
301 mcout << "meandist=" << meandist << '\n';
302 } while (meandist >= precision);
303 *this = straight(ptcurr[0], ptcurr[1]);
304}
DoubleAc sqrt(const DoubleAc &f)
Definition: DoubleAc.cpp:313
#define mcout
Definition: prstream.h:133
double vfloat
Definition: vfloat.h:15

◆ straight() [7/7]

Heed::straight::straight ( straight sl,
int  qsl,
const straight sl_start,
int  anum,
vfloat  precision,
vfloat dist,
point(*)  pt[2],
vfloat mean2dist 
)

Definition at line 142 of file straight.cpp.

146 {
147 pvecerror("void straight::straight(straight* sl, int qsl,...");
148 check_econd11(qsl, < 4, mcerr);
149 straight sl_finish = sl_start;
150 int n;
151 mean2dist = max_vfloat;
152 vfloat mean2dist_prev = max_vfloat;
153 int type_of_cross;
154 point* ptf = new point[qsl];
155 //mcout<<"straight::straight: starting, qsl="<<qsl
156 // <<"\nsl_start="<<sl_start<<'\n';
157 do {
158 mean2dist_prev = mean2dist;
159 mean2dist = 0;
160 *this = sl_finish;
161 for (n = 0; n < qsl; n++) {
162 dist[n] = vecdistance(sl[n], type_of_cross, pt[n]);
163 mean2dist += pow(dist[n], 2);
164 check_econd11(type_of_cross, > 1, mcerr);
165 ptf[n] = pt[n][1];
166 }
167 mean2dist /= qsl;
168 if (mean2dist > 0) mean2dist = sqrt(mean2dist);
169 sl_finish = straight(ptf, qsl, anum);
170 //mcout<<"straight::straight: mean2dist_prev="<<mean2dist_prev
171 // <<" mean2dist="<<mean2dist<<'\n';
172 //for( n=0; n<qsl; n++)
173 //{
174 // mcout<<"pt[n][0]="<<pt[n][0]<<'\n';
175 // mcout<<"pt[n][1]="<<pt[n][1]<<'\n';
176 //}
177 } while (mean2dist_prev < mean2dist ||
178 (mean2dist != 0 && mean2dist_prev - mean2dist > precision));
179 //mcout<<"straight::straight: finishinging, *this="<<(*this)<<'\n';
180 delete ptf;
181}
DoubleAc pow(const DoubleAc &f, double p)
Definition: DoubleAc.cpp:336
vfloat vecdistance(const straight &sl, int &type_of_cross, point pt[2]) const
Definition: straight.cpp:75
#define max_vfloat
Definition: vfloat.h:14

Member Function Documentation

◆ check_point_in()

int Heed::straight::check_point_in ( const point fp,
vfloat  prec 
) const

Definition at line 50 of file straight.cpp.

50 {
51 pvecerror("int straight::check_point_in(point fp, vfloat prec)");
52 vfloat f = distance(fp);
53 if (f <= prec) return 1;
54 return 0;
55}
vfloat distance(const straight &sl, int &type_of_cross, point pt[2]) const
Definition: straight.cpp:137

Referenced by Heed::plane::plane(), and vecdistance().

◆ cross()

point Heed::straight::cross ( const straight sl,
vfloat  prec 
) const

Definition at line 56 of file straight.cpp.

56 {
57 pvecerror("point straight::cross(straight& sl, vfloat prec)");
58 point pt[2];
59 int type_of_cross;
60 vfloat f = vecdistance(sl, type_of_cross, &pt[0]);
61 point ptt(dv0);
62 if (type_of_cross == 2 || type_of_cross == 3) {
63 vecerror = type_of_cross;
64 return ptt;
65 }
66 if (fabs(f) <= prec) {
67 vecerror = 0;
68 return pt[0];
69 } else {
70 vecerror = 1;
71 return ptt;
72 }
73}
DoubleAc fabs(const DoubleAc &f)
Definition: DoubleAc.h:616
vec dv0(0, 0, 0)
int vecerror
Definition: vec.cpp:31

Referenced by Heed::polyline::cross(), Heed::plane::plane(), and Heed::polygon::polygon().

◆ distance() [1/3]

vfloat Heed::straight::distance ( const point fpt) const

Definition at line 183 of file straight.cpp.

183 {
184 pvecerror("vfloat straight::distance(point& fpt)");
185 if (fpt == piv) return 0.0;
186 vec v = fpt - piv;
187 return length(v) * sin2vec(dir, v); // should be positive
188}
Definition: vec.h:248
vfloat sin2vec(const vec &r1, const vec &r2)
Definition: vec.cpp:183

◆ distance() [2/3]

vfloat Heed::straight::distance ( const point fpt,
point fcpt 
) const

Definition at line 189 of file straight.cpp.

189 {
190 pvecerror("vfloat straight::distance(point& fpt, point& fcpt)");
191 if (fpt == piv) {
192 fcpt = piv;
193 return 0.0;
194 }
195 vec v = fpt - piv;
196 vfloat len = length(v);
197 fcpt = piv + len * cos2vec(dir, v) * dir;
198 return length(v) * sin2vec(dir, v);
199}
vfloat cos2vec(const vec &r1, const vec &r2)
Definition: vec.cpp:142

◆ distance() [3/3]

vfloat Heed::straight::distance ( const straight sl,
int &  type_of_cross,
point  pt[2] 
) const

◆ Gdir()

vec Heed::straight::Gdir ( void  ) const
inline

◆ get_components()

void Heed::straight::get_components ( ActivePtr< absref_transmit > &  aref_tran)
protectedvirtual

Reimplemented from absref.

Definition at line 23 of file straight.cpp.

23 {
24 aref_tran.pass(new absref_transmit(2, aref));
25}
static absrefabsref::*[2] aref
Definition: straight.h:37

◆ Gpiv()

point Heed::straight::Gpiv ( void  ) const
inline

Definition at line 30 of file straight.h.

30{ return piv; }

Referenced by Heed::plane::cross(), Heed::plane::plane(), and Heed::polyline_pl::polyline_pl().

◆ operator=()

straight & Heed::straight::operator= ( const straight fsl)
inline

Definition at line 44 of file straight.h.

44 {
45 piv = fsl.piv;
46 dir = fsl.dir;
47 return *this;
48 }

◆ vecdistance() [1/2]

vfloat Heed::straight::vecdistance ( const straight sl,
int &  type_of_cross,
point  pt[2] 
) const

Definition at line 75 of file straight.cpp.

76 {
77 pvecerror("vfloat straight::distance(const straight& sl, int type_of_cross, "
78 "point pt[2])");
79 pt[0] = point();
80 pt[1] = point();
81 type_of_cross = 0;
82 straight s1, s2;
83 s1 = *this;
84 s2 = sl; // s2 may be changed
85 //mcout<<s1<<s2;
86 if (s1.piv == s2.piv) { // the same origin point
87 if (check_par(s1.dir, s2.dir, 0.0) != 0) // parallel or anti-parallel
88 {
89 type_of_cross = 3;
90 return 0.0; // coincidence
91 } else { // crossed in piv;
92 return 0.0;
93 }
94 }
95 if (check_par(s1.dir, s2.dir, 0.0) != 0) // parallel or anti-parallel
96 {
97 if (s1.check_point_in(s2.piv, 0.0) == 1) { // point in => the same line
98 type_of_cross = 3;
99 return 0.0;
100 } else // not crossed
101 {
102 type_of_cross = 2; // different parallel lines
103 return s1.distance(s2.piv);
104 }
105 } // now we know that the lines are not parallel
106
107 basis bs(s1.dir, s2.dir, "local");
108 //ez is parallel to s1.dir, ez=unit_vec(s1.dir)
109 //ey is perpendicular to plane which have s1.dir and s2.dir,
110 // ey=unit_vec(ez||s2.dir)
111 //ex is vector product of ey and ez, ex=ey||ez
112 //mcout<<bs;
113 fixsyscoor scl(&s1.piv, &bs, "local");
114 //mcout<<scl;
115 plane pn(point(0, 0, 0), vec(1, 0, 0)); // assumed to be in scl
116 // This plane is defined by
117 //mcout<<pn;
118 s2.up(&scl);
119 //mcout<<s2;
120 pt[1] = pn.cross(s2);
121 //mcout<<pt;
122 if (pt[1].v.y == 0) {
123 pt[1].down(&scl);
124 pt[0] = pt[1];
125 return 0.0;
126 } else {
127 type_of_cross = 1;
128 vfloat d = pt[1].v.y;
129 pt[0] = pt[1];
130 pt[0].v.y = 0;
131 pt[0].down(&scl);
132 pt[1].down(&scl);
133 return d;
134 }
135}
Definition: vec.h:397
virtual void down(const abssyscoor *fasc)
Definition: vec.cpp:546

Referenced by cross(), distance(), and straight().

◆ vecdistance() [2/2]

point Heed::straight::vecdistance ( const vec  normal,
const straight slt 
)

Definition at line 201 of file straight.cpp.

201 {
202 pvecerror(
203 "vfloat straight::vecdistance(const vec normal, const straight& slt)");
204 if (check_perp(normal, slt.Gdir(), 0.0) == 1) // if it is perp.
205 {
206 mcout << "straight::vecdistance: normal=" << normal
207 << " slt.Gdir()=" << slt.Gdir();
208 vecerror = 1;
209 return point(0, 0, 0);
210 }
211 basis bash(dir, normal, "temprorary");
212 fixsyscoor sc(&piv, &bash, "temprorary");
213 straight slh = slt;
214 slh.up(&sc);
215 plane pn = plane(point(0, 0, 0), vec(1, 0, 0));
216 return pn.cross(slh);
217}

Friends And Related Function Documentation

◆ apeq

int apeq ( const straight sl1,
const straight sl2,
vfloat  prec 
)
friend

Definition at line 40 of file straight.cpp.

40 {
41 pvecerror("int apeq(const straight &sl1, const straight &sl2, vfloat "
42 "prec=vprecision)");
43 int i = check_par(sl1.dir, sl2.dir, prec);
44 if (i == 0) return 0;
45 if (apeq(sl1.piv, sl2.piv, prec)) return 1;
46 if (sl1.check_point_in(sl2.piv, prec) == 1) return 1;
47 return 0;
48}
friend int apeq(const straight &sl1, const straight &sl2, vfloat prec)
Definition: straight.cpp:40

◆ not_apeq

int not_apeq ( const straight sl1,
const straight sl2,
vfloat  prec 
)
friend

Definition at line 75 of file straight.h.

75 {
76 return apeq(sl1, sl2, prec) == 1 ? 0 : 1;
77 }

◆ operator!=

int operator!= ( const straight sl1,
const straight sl2 
)
friend

Definition at line 71 of file straight.h.

71 {
72 return sl1 == sl2 ? 0 : 1;
73 }

◆ operator<<

std::ostream & operator<< ( std::ostream &  file,
const straight s 
)
friend

Definition at line 306 of file straight.cpp.

306 {
307 Ifile << "straight (line):\n";
308 indn.n += 2;
309 file << s.piv << s.dir;
310 indn.n -= 2;
311 return file;
312}
indentation indn
Definition: prstream.cpp:13
#define Ifile
Definition: prstream.h:207

◆ operator==

int operator== ( const straight sl1,
const straight sl2 
)
friend

Definition at line 31 of file straight.cpp.

31 {
32 pvecerror("int operator==(const straight &sl1, const straight &sl2)");
33
34 if (!(sl1.dir == sl2.dir || sl1.dir == -sl2.dir)) return 0;
35 if (sl1.piv == sl2.piv) return 1;
36 if (sl1.check_point_in(sl2.piv, 0.0) == 1) return 1;
37 return 0;
38}

Member Data Documentation

◆ aref

absref absref::* Heed::straight::aref
staticprotected
Initial value:

Definition at line 37 of file straight.h.

Referenced by get_components().

◆ dir

vec Heed::straight::dir
protected

Definition at line 28 of file straight.h.

Referenced by distance(), Gdir(), operator=(), straight(), and vecdistance().

◆ piv

point Heed::straight::piv
protected

Definition at line 27 of file straight.h.

Referenced by distance(), Gpiv(), operator=(), straight(), and vecdistance().


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