Garfield++ v1r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
polyline.h
Go to the documentation of this file.
1#ifndef POLYLINE_H
2#define POLYLINE_H
7
8/*
9Copyright (c) 2000 Igor B. Smirnov
10
11The file can be used, copied, modified, and distributed
12according to the terms of GNU Lesser General Public License version 2.1
13as published by the Free Software Foundation,
14and provided that the above copyright notice, this permission notice,
15and notices about any modifications of the original text
16appear in all copies and in supporting documentation.
17The file is provided "as is" without express or implied warranty.
18*/
19
20namespace Heed {
21
22// **** polyline ****
23
24#define vec_polyline_index 5
25
26class polyline : public absref {
27 protected:
28 int qpt;
30 int qsl;
32
33 public:
34 int Gqpt(void) const { return qpt; }
35 point Gpt(int n) const { // there is no funname line, check directly
36 //check_econd12(n , >= , qpt , mcerr);
37 if (n >= qpt) {
38 mcerr << "error in polyline:Gpt(int n): n>qpt: n=" << n << " qpt=" << qpt
39 << '\n';
41 }
42 return pt[n];
43 }
44 int Gqsl(void) const { return qsl; }
45 straight Gsl(int n) const {
46 if (n >= qsl) {
47 mcerr << "error in polyline:Gpt(int n): n>qsl: n=" << n << " qsl=" << qsl
48 << '\n';
50 }
51 return sl[n];
52 }
53
54 protected:
56 virtual void get_components(ActivePtr<absref_transmit>& aref_tran);
57
58 public:
59
60 int check_point_in(const point& fpt, vfloat prec) const;
61 // 0 point is not in
62 // 1 point coincides with an edge
63 // 2 point is inside an interval
64
65 int cross(const straight& fsl, point* pc, int& qpc, polyline* pl, int& qpl,
66 vfloat prec) const;
67 //If straight line goes exactly by segment of polyline,
68 //the fuction gives two end points of adjacent segments and the
69 //segment itself.
70 //If one of the points is common, it is given several times.
71 //For example, if line crosses break point the point is given two times.
72 vfloat dist_two_inter(polyline& pl, vfloat prec) const;
73 // Distance between two intervals, polylines with one segment of line
74 // and two points
75 vfloat distance(const point& fpt) const;
76 vfloat distance(const point& fpt, point& cpt) const;
77
78 protected:
79 void polyline_init(const point* fpt, int fqpt);
80 //void polyline_init(straight* fsl, int fqsl);
81 void polyline_del(void) {
82 if (pt != NULL) {
83 delete[] pt;
84 pt = NULL;
85 }
86 if (sl != NULL) {
87 delete[] sl;
88 sl = NULL;
89 }
90 if (aref != NULL) {
91 delete[] aref;
92 aref = NULL;
93 }
94 }
95
96 public:
97 polyline(void) {
98 point ptl;
99 polyline_init(&ptl, 0);
100 }
101
102 polyline(polyline& pl);
103 polyline(const polyline& pl);
104
105 polyline(const point* fpt, int fqpt);
106 polyline(const point& fpt1, const point& fpt2); // interval
107
108 polyline& operator=(const polyline& fpl);
109
111 friend int plane::cross(const polyline& pll, point* crpt, int& qcrpt,
112 polyline* crpll, int& qcrpll, vfloat prec) const;
113 friend std::ostream& operator<<(std::ostream& file, const polyline& p);
114
115};
116
117int cross4pllines(const polyline pl[4], vfloat precision, straight& sl,
118 point ptc[4][2]);
119// Draws straight line via 4 intervals.
120// returns 1 if line is drawn and 0 otherwise
121
122std::ostream& operator<<(std::ostream& file, const polyline& p);
123
124// **** polyline in plane ****
125
126class polyline_pl : public polyline {
127 protected:
129
130 public:
131 plane Gpn(void) const { return pn; }
132
133 protected:
135 virtual void get_components(ActivePtr<absref_transmit>& aref_tran);
136 public:
137 polyline_pl(void) : polyline(), pn() { ; }
138 polyline_pl(const polyline_pl& pl) : polyline(pl), pn(pl.pn) { ; }
139 polyline_pl(const plane& fpn, const point* fpt, int fqpt)
140 : polyline(fpt, fqpt), pn(fpn) {
141 ;
142 }
144 polyline_pl(const polyline& pl);
145
146 polyline_pl& operator=(const polyline_pl& fpl);
147 friend std::ostream& operator<<(std::ostream& file, const polyline_pl& p);
148};
149
150std::ostream& operator<<(std::ostream& file, const polyline_pl& p);
151
152// **** polygon (in plane) ****
153
154class polygon : public polyline_pl {
155 public:
156 //vfloat area(void);
158 int check_point_in(const point& fpt, vfloat prec) const;
159 // 0 point is not in
160 // 1 point coincides with an edge
161 // 2 point is inside an interval of border
162 // 3 point is inside body
163 point cross(const straight& fsl, vfloat prec) const;
164 // if no cross, returns vecerror=1.
165
166 int range(const point& fpt, const vec& dir, vfloat& rng, point& fptenr,
167 vfloat prec) const;
168 polygon& operator=(const polygon& fpl);
169 polygon(void) : polyline_pl(), s_convex(0) { ; }
170 polygon(const polygon& plg) : polyline_pl((polyline_pl) plg) {
171 s_convex = plg.s_convex;
172 }
173 polygon(const polyline_pl& fpl, int fs_convex)
174 : polyline_pl(fpl), s_convex(fs_convex) {
175 if (fpl.Gqpt() < 4 ||
176 fpl.Gpt(0) !=
177 fpl.Gpt(qpt -
178 1)) { // 4 repeats 1, so different points are 3 or more
179 mcerr << "ERROR in polygon::polygon(polyline_pl& fpl, int fs_convex)\n";
180 mcerr << "fpl.Gqpt() < 4 || fpl.Gpt(0)!=fpl.Gpt(qpt-1)\n";
181 spexit(mcerr);
182 }
183 }
184 polygon(const straight* fsl, int fqsl, vfloat prec);
185 // Prec is used to find crossing points of straight lines
186
187};
188std::ostream& operator<<(std::ostream& file, const polygon& p);
189
190// *** rectangle ***
191
192class rectangle : public polygon {
193 public:
194 point piv; // central point
195 vec dir1; // directions of sides, unit length
196 vec dir2; // directions of sides, unit length
197 vfloat dim[2]; // dimensions
198 rectangle(void) : polygon() { ; }
199 rectangle(const point& fpiv, vec fdir[2], vfloat fdim[2], vfloat prec);
200 // Prec is used to check that sides are perpendicular and
201 // at initing of the polygon wia straight lines.
202 protected:
203 static absref(absref::* aref_rct[4]);
204 virtual void get_components(ActivePtr<absref_transmit>& aref_tran);
205};
206std::ostream& operator<<(std::ostream& file, const rectangle& f);
207
208// **** special quadrangle **** for cathode strip shamber
209// 2 lines are going from a point of origin
210
211class spquadr : public polygon {
212 protected:
215 vfloat awidth; // width of total plane in units of radians
216 public:
217 point Gpiv(void) const { return piv; }
218 vec Gdir1(void) const { return dir1; }
219 vec Gdir2(void) const { return dir2; }
220 vfloat Gawidth(void) const { return awidth; }
221
222 protected:
223 static absref(absref::* aref_sp[4]);
224 virtual void get_components(ActivePtr<absref_transmit>& aref_tran);
225 public:
226
227 vfloat apos(const point& fpt) const // position in units of radians
228 {
229 // it is assumed that the point is inside
230 //mcout<<"dir1="<<dir1<<"vec(fpt-piv)="<<vec(fpt-piv);
231 return acos(cos2vec(dir1, vec(fpt - piv)));
232 }
233 vfloat apos(const straight& fsl, vfloat prec) const {
234 point pth = cross(fsl, prec);
235 if (vecerror != 0) return 0.0;
236 return apos(pth);
237 }
238 vfloat perpos(const point& fpt) const // perpendicular position,
239 //distance from basis sl[0]
240 { // it is assumed that the point is inside
241 vfloat r = sl[0].distance(fpt);
242 return r;
243 }
244 vfloat perpos(const straight& fsl, vfloat prec) const {
245 point pth = cross(fsl, prec);
246 if (vecerror != 0) return 0.0;
247 return perpos(pth);
248 }
249 point pt_angle_rad(vfloat rad, vfloat angle);
250
251 spquadr(void) : polygon(), piv(), dir1(), dir2(), awidth(0) { ; }
252
253 spquadr(spquadr& sq);
254 spquadr(const spquadr& sq);
255
256 spquadr(const point& fpiv, const straight& sl1, const straight& sl2,
257 const vec& fdir1, const vec& fdir2, vfloat prec);
258
259 friend std::ostream& operator<<(std::ostream& file, const spquadr& p);
260
261 private:
262 spquadr(const point& fpiv, const straight& /*sl1*/, const straight& /*sl2*/,
263 const vec& fdir1, const vec& fdir2, polygon& fplgn)
264 : polygon(fplgn),
265 piv(fpiv),
266 dir1(unit_vec(fdir1)),
267 dir2(unit_vec(fdir2)) {
269 }
270};
271
272std::ostream& operator<<(std::ostream& file, const spquadr& p);
273
274}
275
276#endif
DoubleAc acos(const DoubleAc &f)
Definition: DoubleAc.cpp:488
#define spexit(stream)
Definition: FunNameStack.h:536
point cross(const straight &sl) const
Definition: plane.cpp:77
int range(const point &fpt, const vec &dir, vfloat &rng, point &fptenr, vfloat prec) const
Definition: polyline.cpp:399
polygon(void)
Definition: polyline.h:169
polygon(const polygon &plg)
Definition: polyline.h:170
int check_point_in(const point &fpt, vfloat prec) const
Definition: polyline.cpp:345
polygon(const polyline_pl &fpl, int fs_convex)
Definition: polyline.h:173
polygon & operator=(const polygon &fpl)
Definition: polyline.cpp:336
polyline_pl(const plane &fpn, const point *fpt, int fqpt)
Definition: polyline.h:139
virtual void get_components(ActivePtr< absref_transmit > &aref_tran)
Definition: polyline.cpp:242
friend std::ostream & operator<<(std::ostream &file, const polyline_pl &p)
Definition: polyline.cpp:274
polyline_pl & operator=(const polyline_pl &fpl)
Definition: polyline.cpp:266
polyline_pl(const polyline_pl &pl)
Definition: polyline.h:138
static absrefabsref::* aref_pl
Definition: polyline.h:134
plane Gpn(void) const
Definition: polyline.h:131
polyline & operator=(const polyline &fpl)
Definition: polyline.cpp:43
int Gqsl(void) const
Definition: polyline.h:44
point * pt
Definition: polyline.h:29
friend std::ostream & operator<<(std::ostream &file, const polyline &p)
Definition: polyline.cpp:225
straight * sl
Definition: polyline.h:31
point Gpt(int n) const
Definition: polyline.h:35
void polyline_init(const point *fpt, int fqpt)
Definition: polyline.cpp:50
straight Gsl(int n) const
Definition: polyline.h:45
vfloat dist_two_inter(polyline &pl, vfloat prec) const
Definition: polyline.cpp:129
virtual void get_components(ActivePtr< absref_transmit > &aref_tran)
Definition: polyline.cpp:18
absref ** aref
Definition: polyline.h:55
int Gqpt(void) const
Definition: polyline.h:34
friend int plane::cross(const polyline &pll, point *crpt, int &qcrpt, polyline *crpll, int &qcrpll, vfloat prec) const
~polyline(void)
Definition: polyline.h:110
int check_point_in(const point &fpt, vfloat prec) const
Definition: polyline.cpp:79
vfloat distance(const point &fpt) const
Definition: polyline.cpp:150
void polyline_del(void)
Definition: polyline.h:81
polyline(void)
Definition: polyline.h:97
rectangle(void)
Definition: polyline.h:198
static absrefabsref::*[4] aref_rct
Definition: polyline.h:203
vfloat dim[2]
Definition: polyline.h:197
virtual void get_components(ActivePtr< absref_transmit > &aref_tran)
Definition: polyline.cpp:433
friend std::ostream & operator<<(std::ostream &file, const spquadr &p)
Definition: polyline.cpp:534
vfloat apos(const straight &fsl, vfloat prec) const
Definition: polyline.h:233
virtual void get_components(ActivePtr< absref_transmit > &aref_tran)
Definition: polyline.cpp:492
point Gpiv(void) const
Definition: polyline.h:217
vfloat apos(const point &fpt) const
Definition: polyline.h:227
vfloat awidth
Definition: polyline.h:215
point pt_angle_rad(vfloat rad, vfloat angle)
Definition: polyline.cpp:496
vfloat perpos(const point &fpt) const
Definition: polyline.h:238
vec Gdir2(void) const
Definition: polyline.h:219
vec Gdir1(void) const
Definition: polyline.h:218
static absrefabsref::*[4] aref_sp
Definition: polyline.h:223
spquadr(void)
Definition: polyline.h:251
vfloat Gawidth(void) const
Definition: polyline.h:220
vfloat perpos(const straight &fsl, vfloat prec) const
Definition: polyline.h:244
vfloat distance(const straight &sl, int &type_of_cross, point pt[2]) const
Definition: straight.cpp:137
Definition: vec.h:134
Definition: vec.h:477
Definition: vec.h:248
Definition: BGMesh.cpp:3
std::ostream & operator<<(std::ostream &file, const BGMesh &bgm)
Definition: BGMesh.cpp:22
int cross4pllines(const polyline pl[4], vfloat precision, straight &sl, point ptc[4][2])
Definition: polyline.cpp:203
#define mcerr
Definition: prstream.h:135
vfloat cos2vec(const vec &r1, const vec &r2)
Definition: vec.cpp:142
int vecerror
Definition: vec.cpp:31
double vfloat
Definition: vfloat.h:15