Garfield++ v1r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
plane.cpp
Go to the documentation of this file.
2/*
3Copyright (c) 2000 Igor B. Smirnov
4
5The file can be used, copied, modified, and distributed
6according to the terms of GNU Lesser General Public License version 2.1
7as published by the Free Software Foundation,
8and provided that the above copyright notice, this permission notice,
9and notices about any modifications of the original text
10appear in all copies and in supporting documentation.
11The file is provided "as is" without express or implied warranty.
12*/
13
14namespace Heed {
15
16// **** plane ****
17
20
21void plane::get_components(ActivePtr<absref_transmit>& aref_tran) {
22 aref_tran.pass(new absref_transmit(2, aref));
23}
24
25plane::plane(const straight& sl, const point& pt) : piv(sl.Gpiv()), dir() {
26 pvecerror("plane::plane( const straight& sl, const point& pt)");
27 int i = sl.check_point_in(pt, 0.0);
28 if (i != 0)
29 vecerror = 1;
30 else
31 dir = unit_vec(sl.Gdir() || (pt - sl.Gpiv()));
32}
33plane::plane(const straight& sl1, const straight& sl2, vfloat prec)
34 : piv(sl1.Gpiv()), dir() {
36 "plane::plane( const straight& sl1, const straight& sl2, vfloat prec)");
37 point pt = sl1.cross(sl2, prec);
38 if (vecerror == 0) {
39 piv = pt;
40 dir = unit_vec(sl1.Gdir() || sl2.Gdir());
41 } else if (vecerror == 2) // different parallel lines
42 {
43 vecerror = 0;
44 dir = unit_vec(sl1.Gdir() || (sl2.Gpiv() - sl1.Gpiv()));
45 }
46 // otherwise vecerror != 0
47}
48
49int operator==(const plane& pl1, const plane& pl2) {
50 pvecerror("int operator==(const plane &pl1, const plane &pl2)");
51
52 if (!(pl1.dir == pl2.dir || pl1.dir == -pl2.dir)) return 0;
53 if (pl1.piv == pl2.piv) return 1;
54 if (pl1.check_point_in(pl2.piv, 0) == 1)
55 return 1;
56 else
57 return 0;
58}
59
60int apeq(const plane& pl1, const plane& pl2, vfloat prec) {
61 pvecerror("int apeq(const plane &pl1, const plane &pl2, vfloat prec)");
62 if (check_par(pl1.dir, pl2.dir, prec) == 0) return 0;
63 if (apeq(pl1.piv, pl2.piv, prec) == 1) return 1;
64 if (pl1.check_point_in(pl2.piv, prec) == 1)
65 return 1;
66 else
67 return 0;
68}
69
70int plane::check_point_in(const point& fp, vfloat prec) const {
71 pvecerror("int plane::check_point_in(point fp, vfloat prec)");
72 vfloat f = distance(fp);
73 if (f < prec) return 1;
74 return 0;
75}
76
77point plane::cross(const straight& sl) const {
78 pvecerror("point plane::cross(straight &sl)");
79 point slpiv = sl.Gpiv();
80 vec sldir = sl.Gdir();
81 vfloat r = dir * sldir;
82 if (r == 0.0) {
83 if (slpiv == piv || check_perp((piv - slpiv), dir, 0.0) == 1) {
84 // Line is in plane
85 vecerror = 3;
86 } else {
87 vecerror = 2;
88 }
89 return point();
90 }
91
92 vfloat t = (piv.v - slpiv.v) * dir;
93 return point(slpiv.v + t / r * sldir);
94}
95
96straight plane::cross(const plane& pl) const {
97 pvecerror("point plane::cross(plane &pl)");
98 point plpiv = pl.Gpiv();
99 vec pldir = pl.Gdir();
100 vec a = dir || pldir; //direction of the overall straight lines
101 if (length(a) == 0) {
102 if (plpiv == piv || check_par(pldir, dir, 0.0) != 0) { // planes coinsides
103 vecerror = 3;
104 return straight();
105 } else {
106 vecerror = 2;
107 return straight();
108 }
109 }
110 a = unit_vec(a);
111 vec c = a || dir; //perpend. for ov. str.
112 straight st(piv, c);
113 point pt = pl.cross(st); //one point on ov. str.
114 return straight(pt, a); //overall straight
115}
116
117int plane::cross(const polyline& pll, point* crpt, int& qcrpt, polyline* crpll,
118 int& qcrpll, vfloat prec) const {
119 pvecerror("int plane::cross(polyline &pll, ...");
120
121 int n;
122 qcrpt = 0;
123 qcrpll = 0;
124 for (n = 0; n < pll.qsl; n++) {
125 point cpt = cross(pll.sl[n]);
126 if (vecerror == 3) // the line is in the plane
127 crpll[qcrpll++] = polyline(&(pll.pt[n]), 2);
128 else if (vecerror != 0)
129 vecerror = 0;
130 else {
131 vec v1 = cpt - pll.pt[n];
132 if (length(v1) < prec) {
133 if (n == 0) // otherwise it is probably included on the previous step
134 {
135 crpt[qcrpt++] = cpt;
136 }
137 } else {
138 vec v2 = cpt - pll.pt[n + 1];
139 if (length(v2) < prec)
140 crpt[qcrpt++] = cpt;
141 else if (check_par(v1, v2, prec) == -1)
142 // anti-parallel vectors, point inside borders
143 crpt[qcrpt++] = cpt;
144 }
145 }
146 }
147 if (qcrpt > 0 || qcrpll > 0)
148 return 1;
149 else
150 return 0;
151}
152
153vfloat plane::distance(const point& fpt) const {
154 pvecerror("vfloat plane::distance(point& fpt)");
155 if (fpt == piv) return 0.0;
156 vec v = fpt - piv;
157 return abslt(v * dir); // relys that dir is unit length vector
158}
159
160std::ostream& operator<<(std::ostream& file, const plane& pl) {
161 Ifile << "plane:\n";
162 indn.n += 2;
163 file << pl.piv << pl.dir;
164 indn.n -= 2;
165 return file;
166}
167
168}
static absrefabsref::*[2] aref
Definition: plane.h:40
point cross(const straight &sl) const
Definition: plane.cpp:77
plane()
Definition: plane.h:44
point Gpiv(void) const
Definition: plane.h:31
point piv
Definition: plane.h:28
vec dir
Definition: plane.h:29
vec Gdir(void) const
Definition: plane.h:34
int check_point_in(const point &fp, vfloat prec) const
Definition: plane.cpp:70
virtual void get_components(ActivePtr< absref_transmit > &aref_tran)
Definition: plane.cpp:21
vfloat distance(const point &fpt) const
Definition: plane.cpp:153
point * pt
Definition: polyline.h:29
straight * sl
Definition: polyline.h:31
point cross(const straight &sl, vfloat prec) const
Definition: straight.cpp:56
vec Gdir(void) const
Definition: straight.h:31
int check_point_in(const point &fp, vfloat prec) const
Definition: straight.cpp:50
point Gpiv(void) const
Definition: straight.h:30
Definition: vec.h:134
Definition: vec.h:477
vec v
Definition: vec.h:479
Definition: vec.h:248
Definition: BGMesh.cpp:3
int apeq(const circumf &f1, const circumf &f2, vfloat prec)
Definition: circumf.cpp:45
std::ostream & operator<<(std::ostream &file, const BGMesh &bgm)
Definition: BGMesh.cpp:22
int operator==(const circumf &f1, const circumf &f2)
Definition: circumf.cpp:36
indentation indn
Definition: prstream.cpp:13
#define Ifile
Definition: prstream.h:207
int vecerror
Definition: vec.cpp:31
#define pvecerror(string)
Definition: vec.h:52
double vfloat
Definition: vfloat.h:15
vfloat abslt(vfloat f)
Definition: vfloat.h:19