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

#include <polyline.h>

+ Inheritance diagram for Heed::polygon:

Public Member Functions

int check_point_in (const point &fpt, vfloat prec) const
 
point cross (const straight &fsl, vfloat prec) const
 
int range (const point &fpt, const vec &dir, vfloat &rng, point &fptenr, vfloat prec) const
 
polygonoperator= (const polygon &fpl)
 
 polygon (void)
 
 polygon (const polygon &plg)
 
 polygon (const polyline_pl &fpl, int fs_convex)
 
 polygon (const straight *fsl, int fqsl, vfloat prec)
 
- Public Member Functions inherited from Heed::polyline_pl
plane Gpn (void) const
 
 polyline_pl (void)
 
 polyline_pl (const polyline_pl &pl)
 
 polyline_pl (const plane &fpn, const point *fpt, int fqpt)
 
 polyline_pl (polyline &pl)
 
 polyline_pl (const polyline &pl)
 
polyline_ploperator= (const polyline_pl &fpl)
 
- Public Member Functions inherited from Heed::polyline
int Gqpt (void) const
 
point Gpt (int n) const
 
int Gqsl (void) const
 
straight Gsl (int n) const
 
int check_point_in (const point &fpt, vfloat prec) const
 
int cross (const straight &fsl, point *pc, int &qpc, polyline *pl, int &qpl, vfloat prec) const
 
vfloat dist_two_inter (polyline &pl, vfloat prec) const
 
vfloat distance (const point &fpt) const
 
vfloat distance (const point &fpt, point &cpt) const
 
 polyline (void)
 
 polyline (polyline &pl)
 
 polyline (const polyline &pl)
 
 polyline (const point *fpt, int fqpt)
 
 polyline (const point &fpt1, const point &fpt2)
 
polylineoperator= (const polyline &fpl)
 
 ~polyline (void)
 
- 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)
 

Public Attributes

int s_convex
 

Additional Inherited Members

- Protected Member Functions inherited from Heed::polyline_pl
virtual void get_components (ActivePtr< absref_transmit > &aref_tran)
 
- Protected Member Functions inherited from Heed::polyline
virtual void get_components (ActivePtr< absref_transmit > &aref_tran)
 
void polyline_init (const point *fpt, int fqpt)
 
void polyline_del (void)
 
- Protected Attributes inherited from Heed::polyline_pl
plane pn
 
- Protected Attributes inherited from Heed::polyline
int qpt
 
pointpt
 
int qsl
 
straightsl
 
absref ** aref
 
- Static Protected Attributes inherited from Heed::polyline_pl
static absrefabsref::* aref_pl = (absref absref::*)&polyline_pl::pn
 

Detailed Description

Definition at line 154 of file polyline.h.

Constructor & Destructor Documentation

◆ polygon() [1/4]

Heed::polygon::polygon ( void  )
inline

Definition at line 169 of file polyline.h.

169: polyline_pl(), s_convex(0) { ; }

Referenced by polygon(), Heed::rectangle::rectangle(), and Heed::spquadr::spquadr().

◆ polygon() [2/4]

Heed::polygon::polygon ( const polygon plg)
inline

Definition at line 170 of file polyline.h.

170 : polyline_pl((polyline_pl) plg) {
171 s_convex = plg.s_convex;
172 }

◆ polygon() [3/4]

Heed::polygon::polygon ( const polyline_pl fpl,
int  fs_convex 
)
inline

Definition at line 173 of file polyline.h.

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 }
#define spexit(stream)
Definition: FunNameStack.h:536
#define mcerr
Definition: prstream.h:135

◆ polygon() [4/4]

Heed::polygon::polygon ( const straight fsl,
int  fqsl,
vfloat  prec 
)

Definition at line 285 of file polyline.cpp.

286 : polyline_pl(), s_convex(1) {
287 pvecerror("polygon::polygon(const straight* fsl, int fqsl)");
288 check_econd11a(fqsl, < 3, "fqsl cannot be less 3\n", mcerr);
289 int n, m;
290 // now check that either the piv's of lines are not equal to each other,
291 // or the dir's are not parallel.
292 // It does not prove that input data are corrent, but more
293 // explicit prove might take too much time.
294 for (n = 0; n < fqsl - 1; n++)
295 for (m = n + 1; m < fqsl; m++) {
296 if (fsl[n].Gpiv() == fsl[m].Gpiv())
297 if (check_par(fsl[n].Gdir(), fsl[m].Gdir(), 0) !=
298 0) //1 par, -1 antipar
299 {
300 mcerr << "error in polyline_init(straight* fsl, int fqsl):\n"
301 << "Parallel lines with the same pivot cannot form polygin\n";
302 for (int k = 0; k < fqsl; k++)
303 mcout << "n=" << k << " fsl[n]=" << fsl[k];
304 spexit(mcerr);
305 }
306 }
307 int qptl = fqsl + 1;
308 point* ptl = new point[qptl];
309 for (n = 1; n < fqsl; n++) {
310 ptl[n] = fsl[n - 1].cross(fsl[n], prec);
311 if (vecerror != 0) {
312 mcerr << "error in polygon::polygon(straight* fsl, int fqsl):\n"
313 << " straight lines are not crossed properly\n"
314 << "fsl[n-1]=" << fsl[n - 1] << "fsl[n]=" << fsl[n]
315 << "vecerror=" << vecerror << '\n';
316 spexit(mcerr);
317 }
318 }
319 ptl[0] = fsl[fqsl - 1].cross(fsl[0], prec);
320 if (vecerror != 0) {
321 mcerr << "error in polygon::polygon(straight* fsl, int fqsl):\n"
322 << " straight lines are not crossed properly\n"
323 << "fsl[fqsl-1]=" << fsl[fqsl - 1] << "fsl[0]=" << fsl[0]
324 << "vecerror=" << vecerror << '\n';
325 spexit(mcerr);
326 }
327 ptl[fqsl] = ptl[0];
328 plane pnl = plane(fsl[0].Gpiv(), fsl[0].Gdir() || fsl[1].Gdir());
329 polyline_pl pll(pnl, ptl, qptl);
330 *this = polygon(pll, 1);
331
332 delete ptl;
333
334}
#define check_econd11a(a, signb, add, stream)
Definition: FunNameStack.h:395
polygon(void)
Definition: polyline.h:169
Definition: vec.h:477
#define mcout
Definition: prstream.h:133
int vecerror
Definition: vec.cpp:31
#define pvecerror(string)
Definition: vec.h:52

Member Function Documentation

◆ check_point_in()

int Heed::polygon::check_point_in ( const point fpt,
vfloat  prec 
) const

Definition at line 345 of file polyline.cpp.

345 {
346 pvecerror("int polygon::check_point_in(point& fpt)");
347 int i;
348 if ((i = polyline::check_point_in(fpt, prec)) > 0) {
349 return i;
350 }
351 if ((i = pn.check_point_in(fpt, prec)) == 0) {
352 return i;
353 }
354 /* The idea of the following algorithm is circulating around the polygon
355 and finding of two points, one gives the minimum angle relatively
356 some(any) direction, another gives the maximal angle.
357 The point resides inside polygon if they are the same at the end of
358 circulation.
359 */
360 point endpt[2];
361 endpt[0] = pt[0]; // which is really first or last, depends on pn.Gdir()
362 endpt[1] = pt[0];
363 double totang = 0;
364 double ang, ang2;
365 //int s_start[2];
366 //s_start[0]=0;
367 //s_start[1]=0;
368 int n;
369 for (n = 0; n < qpt - 1; n++) {
370 ang2 = 0.0;
371 ang = ang2projvec((pt[n] - fpt), (pt[n + 1] - fpt), pn.Gdir());
372 if (ang <= M_PI) {
373 // go to opposite direction of clock
374 totang += ang;
375 } else {
376 ang2 = 2 * M_PI - ang;
377 totang -= ang2;
378 }
379 }
380
381 if (fabs(totang) > 6.0) return 3;
382 return 0;
383}
DoubleAc fabs(const DoubleAc &f)
Definition: DoubleAc.h:616
vec Gdir(void) const
Definition: plane.h:34
int check_point_in(const point &fp, vfloat prec) const
Definition: plane.cpp:70
point * pt
Definition: polyline.h:29
int check_point_in(const point &fpt, vfloat prec) const
Definition: polyline.cpp:79
vfloat ang2projvec(const vec &r1, const vec &r2, const vec &normal)
Definition: vec.cpp:212

Referenced by cross().

◆ cross()

point Heed::polygon::cross ( const straight fsl,
vfloat  prec 
) const

Definition at line 385 of file polyline.cpp.

385 {
386 pvecerror("point polygon::cross(straight& fsl)");
387 point cpt = pn.cross(fsl); // does it cross the plane
388 //mcout<<"polygon::cross: cpt="<<cpt;
389 //mcout<<"vecerror="<<vecerror<<'\n';
390 if (vecerror != 0) return cpt;
391 int s = check_point_in(cpt, prec);
392 if (s > 0)
393 return cpt;
394 else {
395 vecerror = 1;
396 return cpt;
397 }
398}
point cross(const straight &sl) const
Definition: plane.cpp:77
int check_point_in(const point &fpt, vfloat prec) const
Definition: polyline.cpp:345

◆ operator=()

polygon & Heed::polygon::operator= ( const polygon fpl)

Definition at line 336 of file polyline.cpp.

336 {
337 mfunname("polygon& polygon::operator=(const polygon& fpl)");
338 polyline_del();
339 polyline_init(fpl.pt, fpl.qpt);
340 pn = fpl.pn;
341 s_convex = fpl.s_convex;
342 return *this;
343}
#define mfunname(string)
Definition: FunNameStack.h:67
void polyline_init(const point *fpt, int fqpt)
Definition: polyline.cpp:50
void polyline_del(void)
Definition: polyline.h:81

Referenced by Heed::rectangle::rectangle().

◆ range()

int Heed::polygon::range ( const point fpt,
const vec dir,
vfloat rng,
point fptenr,
vfloat  prec 
) const

Definition at line 399 of file polyline.cpp.

400 {
401 pvecerror("int polygon::range(const point& fpt, const vec& dir, vfloat& rng, "
402 " point &fptenr)");
403 straight stl(fpt, dir);
404 point pnt = cross(stl, prec);
405 if (vecerror != 0) {
406 vecerror = 0;
407 return 0;
408 }
409 vec dif = pnt - fpt;
410 const int i = check_par(dif, dir, prec);
411 if (i == 1) {
412 rng = length(dif);
413 fptenr = pnt;
414 return 1;
415 } else
416 return 0;
417}
friend int plane::cross(const polyline &pll, point *crpt, int &qcrpt, polyline *crpll, int &qcrpll, vfloat prec) const
Definition: vec.h:248

Member Data Documentation

◆ s_convex

int Heed::polygon::s_convex

Definition at line 157 of file polyline.h.

Referenced by Heed::operator<<(), operator=(), and polygon().


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