Garfield++ 4.0
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
6
7/*
8Copyright (c) 2000 Igor B. Smirnov
9
10The file can be used, copied, modified, and distributed
11according to the terms of GNU Lesser General Public License version 2.1
12as published by the Free Software Foundation,
13and provided that the above copyright notice, this permission notice,
14and notices about any modifications of the original text
15appear in all copies and in supporting documentation.
16The file is provided "as is" without express or implied warranty.
17*/
18
19namespace Heed {
20
21/// Polyline.
22
23class polyline : public absref {
24 protected:
25 int qpt;
27 int qsl;
29
30 public:
31 int Gqpt() const { return qpt; }
32 point Gpt(int n) const {
33 if (n >= qpt) {
34 mcerr << "error in polyline:Gpt(int n): n>qpt: n=" << n << " qpt=" << qpt
35 << '\n';
37 }
38 return pt[n];
39 }
40 int Gqsl() const { return qsl; }
41 straight Gsl(int n) const {
42 if (n >= qsl) {
43 mcerr << "error in polyline:Gpt(int n): n>qsl: n=" << n << " qsl=" << qsl
44 << '\n';
46 }
47 return sl[n];
48 }
49
50 protected:
52 virtual absref_transmit get_components() override;
53
54 public:
55 /// Return whether a point is inside.
56 /// 0 point is not in
57 /// 1 point coincides with an edge
58 /// 2 point is inside an interval
59 int check_point_in(const point& fpt, vfloat prec) const;
60
61 /// If straight line goes exactly by segment of polyline,
62 /// the fuction gives two end points of adjacent segments and the
63 /// segment itself.
64 /// If one of the points is common, it is given several times.
65 /// For example, if line crosses break point the point is given two times.
66 int cross(const straight& fsl, point* pc, int& qpc, polyline* pl, int& qpl,
67 vfloat prec) const;
68 /// Distance between two intervals.
69 vfloat dist_two_inter(polyline& pl, vfloat prec) const;
70 vfloat distance(const point& fpt) const;
71 /// Distance between two points.
72 vfloat distance(const point& fpt, point& cpt) const;
73
74 protected:
75 void polyline_init(const point* fpt, int fqpt);
76 void polyline_del() {
77 if (pt) {
78 delete[] pt;
79 pt = NULL;
80 }
81 if (sl) {
82 delete[] sl;
83 sl = NULL;
84 }
85 if (aref) {
86 delete[] aref;
87 aref = NULL;
88 }
89 }
90
91 public:
93 point ptl;
94 polyline_init(&ptl, 0);
95 }
96
97 polyline(polyline& pl);
98 polyline(const polyline& pl);
99
100 polyline(const point* fpt, int fqpt);
101 polyline(const point& fpt1, const point& fpt2); // interval
102
103 polyline& operator=(const polyline& fpl);
104
106 friend int plane::cross(const polyline& pll, point* crpt, int& qcrpt,
107 polyline* crpll, int& qcrpll, vfloat prec) const;
108 friend std::ostream& operator<<(std::ostream& file, const polyline& p);
109};
110
111/// Draws straight line via 4 intervals.
112/// Returns 1 if line is drawn and 0 otherwise.
113int cross4pllines(const polyline pl[4], vfloat precision, straight& sl,
114 point ptc[4][2]);
115
116std::ostream& operator<<(std::ostream& file, const polyline& p);
117
118/// Polyline in plane.
119
120class polyline_pl : public polyline {
121 protected:
123
124 public:
125 plane Gpn() const { return pn; }
126
127 protected:
129 virtual absref_transmit get_components() override;
130
131 public:
132 polyline_pl() : polyline(), pn() { ; }
133 polyline_pl(const polyline_pl& pl) : polyline(pl), pn(pl.pn) { ; }
134 polyline_pl(const plane& fpn, const point* fpt, int fqpt)
135 : polyline(fpt, fqpt), pn(fpn) {}
137 polyline_pl(const polyline& pl);
138
139 polyline_pl& operator=(const polyline_pl& fpl);
140 friend std::ostream& operator<<(std::ostream& file, const polyline_pl& p);
141};
142
143std::ostream& operator<<(std::ostream& file, const polyline_pl& p);
144
145/// Polygon in plane.
146
147class polygon : public polyline_pl {
148 public:
150 int check_point_in(const point& fpt, vfloat prec) const;
151 // 0 point is not in
152 // 1 point coincides with an edge
153 // 2 point is inside an interval of border
154 // 3 point is inside body
155 point cross(const straight& fsl, vfloat prec) const;
156 // if no cross, returns vecerror=1.
157
158 int range(const point& fpt, const vec& dir, vfloat& rng, point& fptenr,
159 vfloat prec) const;
160 polygon& operator=(const polygon& fpl);
163 s_convex = plg.s_convex;
164 }
165 polygon(const polyline_pl& fpl, int fs_convex)
166 : polyline_pl(fpl), s_convex(fs_convex) {
167 if (fpl.Gqpt() < 4 || fpl.Gpt(0) != fpl.Gpt(qpt - 1)) {
168 mcerr << "ERROR in polygon::polygon(polyline_pl& fpl, int fs_convex)\n";
169 mcerr << "fpl.Gqpt() < 4 || fpl.Gpt(0)!=fpl.Gpt(qpt-1)\n";
170 spexit(mcerr);
171 }
172 }
173 polygon(const straight* fsl, int fqsl, vfloat prec);
174 // Prec is used to find crossing points of straight lines
175};
176std::ostream& operator<<(std::ostream& file, const polygon& p);
177
178/// Rectangle
179
180class rectangle : public polygon {
181 public:
182 /// Central point
184 /// Directions of sides, unit length
186 /// Directions of sides, unit length
188 // Dimensions
189 vfloat dim[2] = {0., 0.};
191 rectangle(const point& fpiv, vec fdir[2], vfloat fdim[2], vfloat prec);
192 // Prec is used to check that sides are perpendicular and
193 // at initing of the polygon via straight lines.
194 protected:
195 static absref absref::* aref_rct[4];
196 virtual absref_transmit get_components() override;
197};
198std::ostream& operator<<(std::ostream& file, const rectangle& f);
199
200/// Special quadrangle (for cathode strip shamber).
201/// Two lines are going from a point of origin.
202
203class spquadr : public polygon {
204 protected:
207 /// Width of total plane in units of radians
209
210 public:
211 point Gpiv() const { return piv; }
212 vec Gdir1() const { return dir1; }
213 vec Gdir2() const { return dir2; }
214 vfloat Gawidth() const { return awidth; }
215
216 protected:
217 static absref absref::* aref_sp[4];
218 virtual absref_transmit get_components() override;
219
220 public:
221 /// Position in units of radians.
222 vfloat apos(const point& fpt) const {
223 // it is assumed that the point is inside
224 return acos(cos2vec(dir1, vec(fpt - piv)));
225 }
226 vfloat apos(const straight& fsl, vfloat prec) const {
227 point pth = cross(fsl, prec);
228 if (vecerror != 0) return 0.0;
229 return apos(pth);
230 }
231 /// Perpendicular position. Distance from basis sl[0].
232 vfloat perpos(const point& fpt) const {
233 // it is assumed that the point is inside
234 vfloat r = sl[0].distance(fpt);
235 return r;
236 }
237 vfloat perpos(const straight& fsl, vfloat prec) const {
238 point pth = cross(fsl, prec);
239 if (vecerror != 0) return 0.0;
240 return perpos(pth);
241 }
242 point pt_angle_rad(vfloat rad, vfloat angle);
243
244 spquadr() : polygon(), piv(), dir1(), dir2(), awidth(0) {}
245
246 spquadr(spquadr& sq);
247 spquadr(const spquadr& sq);
250 piv = sq.piv;
251 dir1 = sq.dir1;
252 dir2 = sq.dir2;
253 awidth = sq.awidth;
254 return *this;
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#endif
#define spexit(stream)
Definition: FunNameStack.h:256
Plane, defined by defined by a point and a vector normal to the plane.
Definition: plane.h:24
point cross(const straight &sl) const
Definition: plane.cpp:75
Point.
Definition: vec.h:368
Polygon in plane.
Definition: polyline.h:147
int range(const point &fpt, const vec &dir, vfloat &rng, point &fptenr, vfloat prec) const
Definition: polyline.cpp:393
polygon(const polygon &plg)
Definition: polyline.h:162
int check_point_in(const point &fpt, vfloat prec) const
Definition: polyline.cpp:339
polygon(const polyline_pl &fpl, int fs_convex)
Definition: polyline.h:165
polygon & operator=(const polygon &fpl)
Definition: polyline.cpp:330
Polyline in plane.
Definition: polyline.h:120
polyline_pl(const plane &fpn, const point *fpt, int fqpt)
Definition: polyline.h:134
friend std::ostream & operator<<(std::ostream &file, const polyline_pl &p)
Definition: polyline.cpp:268
polyline_pl & operator=(const polyline_pl &fpl)
Definition: polyline.cpp:260
polyline_pl(const polyline_pl &pl)
Definition: polyline.h:133
virtual absref_transmit get_components() override
Definition: polyline.cpp:236
static absref absref::* aref_pl
Definition: polyline.h:128
plane Gpn() const
Definition: polyline.h:125
Polyline.
Definition: polyline.h:23
polyline & operator=(const polyline &fpl)
Definition: polyline.cpp:43
virtual absref_transmit get_components() override
Definition: polyline.cpp:18
point * pt
Definition: polyline.h:26
friend std::ostream & operator<<(std::ostream &file, const polyline &p)
Definition: polyline.cpp:221
straight * sl
Definition: polyline.h:28
int Gqsl() const
Definition: polyline.h:40
point Gpt(int n) const
Definition: polyline.h:32
void polyline_init(const point *fpt, int fqpt)
Definition: polyline.cpp:50
straight Gsl(int n) const
Definition: polyline.h:41
vfloat dist_two_inter(polyline &pl, vfloat prec) const
Distance between two intervals.
Definition: polyline.cpp:126
absref ** aref
Definition: polyline.h:51
int Gqpt() const
Definition: polyline.h:31
friend int plane::cross(const polyline &pll, point *crpt, int &qcrpt, polyline *crpll, int &qcrpll, vfloat prec) const
void polyline_del()
Definition: polyline.h:76
int check_point_in(const point &fpt, vfloat prec) const
Definition: polyline.cpp:76
vfloat distance(const point &fpt) const
Definition: polyline.cpp:147
Rectangle.
Definition: polyline.h:180
point piv
Central point.
Definition: polyline.h:183
vfloat dim[2]
Definition: polyline.h:189
vec dir1
Directions of sides, unit length.
Definition: polyline.h:185
vec dir2
Directions of sides, unit length.
Definition: polyline.h:187
static absref absref::* aref_rct[4]
Definition: polyline.h:195
virtual absref_transmit get_components() override
Definition: polyline.cpp:428
friend std::ostream & operator<<(std::ostream &file, const spquadr &p)
Definition: polyline.cpp:529
vfloat apos(const straight &fsl, vfloat prec) const
Definition: polyline.h:226
point Gpiv() const
Definition: polyline.h:211
vfloat apos(const point &fpt) const
Position in units of radians.
Definition: polyline.h:222
vfloat awidth
Width of total plane in units of radians.
Definition: polyline.h:208
point pt_angle_rad(vfloat rad, vfloat angle)
Definition: polyline.cpp:491
static absref absref::* aref_sp[4]
Definition: polyline.h:217
vfloat perpos(const point &fpt) const
Perpendicular position. Distance from basis sl[0].
Definition: polyline.h:232
spquadr & operator=(const spquadr &sq)
Definition: polyline.h:248
vfloat Gawidth() const
Definition: polyline.h:214
vec Gdir1() const
Definition: polyline.h:212
vec Gdir2() const
Definition: polyline.h:213
virtual absref_transmit get_components() override
Definition: polyline.cpp:487
vfloat perpos(const straight &fsl, vfloat prec) const
Definition: polyline.h:237
Straight line, as combination of vector and point.
Definition: straight.h:24
vfloat distance(const straight &sl, int &type_of_cross, point pt[2]) const
Definition: straight.cpp:136
Definition: vec.h:179
Definition: BGMesh.cpp:6
std::ostream & operator<<(std::ostream &file, const BGMesh &bgm)
Definition: BGMesh.cpp:37
int vecerror
Definition: vec.cpp:29
DoubleAc acos(const DoubleAc &f)
Definition: DoubleAc.cpp:490
vfloat cos2vec(const vec &r1, const vec &r2)
Definition: vec.cpp:66
int cross4pllines(const polyline pl[4], vfloat precision, straight &sl, point ptc[4][2])
Definition: polyline.cpp:200
double vfloat
Definition: vfloat.h:16
#define mcerr
Definition: prstream.h:128