Garfield++ 4.0
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

Straight line, as combination of vector and point. More...

#include <straight.h>

+ Inheritance diagram for Heed::straight:

Public Member Functions

point Gpiv () const
 
vec Gdir () const
 
 straight ()
 
 straight (const point &fpiv, const vec &fdir)
 
 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)
 
 straight (straight *sl, int qsl, const straight &sl_start, int anum, vfloat precision, vfloat *dist, point(*pt)[2], vfloat &mean2dist)
 
straightoperator= (const straight &fsl)
 Copy assignment operator.
 
 straight (const straight &s)
 Copy constructor.
 
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
 Shortest distance between two lines, may be negative.
 
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)
 
- Public Member Functions inherited from Heed::absref
virtual ~absref ()
 Destructor.
 
virtual void down (const abssyscoor *fasc)
 Convert numbering representation of object to basical system of fasc.
 
virtual void up (const abssyscoor *fasc)
 Convert numbering representation of objects to new system.
 
virtual void turn (const vec &dir, vfloat angle)
 Turn around axis doing via center of coordinate system along dir.
 
virtual void shift (const vec &dir)
 

Protected Member Functions

virtual absref_transmit get_components () override
 

Protected Attributes

point piv
 Origin point, pivot.
 
vec dir
 Direction, unit vector.
 

Static Protected Attributes

static absref absref::* aref [2]
 

Friends

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

Detailed Description

Straight line, as combination of vector and point.

Definition at line 24 of file straight.h.

Constructor & Destructor Documentation

◆ straight() [1/8]

Heed::straight::straight ( )
inline

Definition at line 40 of file straight.h.

40: piv(), dir() {}
point piv
Origin point, pivot.
Definition: straight.h:27
vec dir
Direction, unit vector.
Definition: straight.h:29

Referenced by straight().

◆ straight() [2/8]

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)) {}

◆ straight() [3/8]

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

Definition at line 43 of file straight.h.

43 : piv(fp1), dir() {
44 pvecerror("straight::straight(const point& fp1, const point& fp2)");
45 check_econd12(fp1, ==, fp2, mcerr);
46 dir = unit_vec(fp2 - fp1);
47 }
#define check_econd12(a, sign, b, stream)
Definition: FunNameStack.h:163
#define mcerr
Definition: prstream.h:128
#define pvecerror(string)
Definition: vec.h:28

◆ straight() [4/8]

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/8]

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

Definition at line 216 of file straight.cpp.

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

◆ straight() [6/8]

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

Definition at line 262 of file straight.cpp.

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

◆ straight() [7/8]

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 141 of file straight.cpp.

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

◆ straight() [8/8]

Heed::straight::straight ( const straight s)
inline

Copy constructor.

Definition at line 88 of file straight.h.

88: piv(s.piv), dir(s.dir) {}

Member Function Documentation

◆ check_point_in()

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

Calculate distance of a point from the line and compare it with prec. Return 1 if the point is on the line.

Definition at line 47 of file straight.cpp.

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

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

◆ cross()

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

Figure out whether the line crosses another straight line (within a precision prec).

  • Lines cross in one point (with precision prec) vecerror = 0
  • Lines do not cross vecerror = 1
  • Lines are parallel vecerror = 2
  • Lines are identical vecerror = 3

Definition at line 53 of file straight.cpp.

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

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 179 of file straight.cpp.

179 {
180 pvecerror("vfloat straight::distance(point& fpt)");
181 if (fpt == piv) return 0.0;
182 vec v = fpt - piv;
183 return v.length() * sin2vec(dir, v); // should be positive
184}
vfloat sin2vec(const vec &r1, const vec &r2)
Definition: vec.cpp:107

◆ distance() [2/3]

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

Definition at line 186 of file straight.cpp.

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

◆ distance() [3/3]

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

◆ Gdir()

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

◆ get_components()

absref_transmit Heed::straight::get_components ( )
overrideprotectedvirtual

Reimplemented from Heed::absref.

Definition at line 23 of file straight.cpp.

23 {
24 return absref_transmit(2, aref);
25}
static absref absref::* aref[2]
Definition: straight.h:37

◆ Gpiv()

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

Definition at line 32 of file straight.h.

32{ 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

Copy assignment operator.

Definition at line 82 of file straight.h.

82 {
83 piv = fsl.piv;
84 dir = fsl.dir;
85 return *this;
86 }

◆ vecdistance() [1/2]

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

Shortest distance between two lines, may be negative.

Definition at line 72 of file straight.cpp.

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

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

◆ vecdistance() [2/2]

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

Definition at line 198 of file straight.cpp.

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

Friends And Related Function Documentation

◆ apeq

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

Definition at line 40 of file straight.cpp.

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

◆ operator!=

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

Definition at line 93 of file straight.h.

93 {
94 return sl1 == sl2 ? 0 : 1;
95 }

◆ operator<<

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

Definition at line 302 of file straight.cpp.

302 {
303 Ifile << "straight (line):\n";
304 indn.n += 2;
305 file << s.piv << s.dir;
306 indn.n -= 2;
307 return file;
308}
indentation indn
Definition: prstream.cpp:15
#define Ifile
Definition: prstream.h:195

◆ 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:
= {(absref absref::*)&straight::piv,
(absref absref::*)&straight::dir}

Definition at line 37 of file straight.h.

Referenced by get_components().

◆ dir

vec Heed::straight::dir
protected

Direction, unit vector.

Definition at line 29 of file straight.h.

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

◆ piv

point Heed::straight::piv
protected

Origin point, pivot.

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: