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::polygon Class Reference

Polygon in plane. More...

#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 ()
 
 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 () const
 
 polyline_pl ()
 
 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 () const
 
point Gpt (int n) const
 
int Gqsl () 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
 Distance between two intervals.
 
vfloat distance (const point &fpt) const
 
vfloat distance (const point &fpt, point &cpt) const
 Distance between two points.
 
 polyline ()
 
 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 ()
 
- 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)
 

Public Attributes

int s_convex
 

Additional Inherited Members

- Protected Member Functions inherited from Heed::polyline_pl
virtual absref_transmit get_components () override
 
- Protected Member Functions inherited from Heed::polyline
virtual absref_transmit get_components () override
 
void polyline_init (const point *fpt, int fqpt)
 
void polyline_del ()
 
- 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 absref absref::* aref_pl = (absref absref::*)&polyline_pl::pn
 

Detailed Description

Polygon in plane.

Definition at line 147 of file polyline.h.

Constructor & Destructor Documentation

◆ polygon() [1/4]

Heed::polygon::polygon ( )
inline

Definition at line 161 of file polyline.h.

161: 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 162 of file polyline.h.

162 : polyline_pl((polyline_pl)plg) {
163 s_convex = plg.s_convex;
164 }

◆ polygon() [3/4]

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

Definition at line 165 of file polyline.h.

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

◆ polygon() [4/4]

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

Definition at line 280 of file polyline.cpp.

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

Member Function Documentation

◆ check_point_in()

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

Definition at line 339 of file polyline.cpp.

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

Referenced by cross().

◆ cross()

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

Definition at line 379 of file polyline.cpp.

379 {
380 pvecerror("point polygon::cross(straight& fsl)");
381 point cpt = pn.cross(fsl); // does it cross the plane
382 // mcout<<"polygon::cross: cpt="<<cpt;
383 // mcout<<"vecerror="<<vecerror<<'\n';
384 if (vecerror != 0) return cpt;
385 int s = check_point_in(cpt, prec);
386 if (s > 0)
387 return cpt;
388 else {
389 vecerror = 1;
390 return cpt;
391 }
392}
point cross(const straight &sl) const
Definition: plane.cpp:75
int check_point_in(const point &fpt, vfloat prec) const
Definition: polyline.cpp:339

◆ operator=()

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

Definition at line 330 of file polyline.cpp.

330 {
331 mfunname("polygon& polygon::operator=(const polygon& fpl)");
332 polyline_del();
333 polyline_init(fpl.pt, fpl.qpt);
334 pn = fpl.pn;
335 s_convex = fpl.s_convex;
336 return *this;
337}
#define mfunname(string)
Definition: FunNameStack.h:45
void polyline_init(const point *fpt, int fqpt)
Definition: polyline.cpp:50
void polyline_del()
Definition: polyline.h:76

Referenced by Heed::spquadr::operator=(), and Heed::rectangle::rectangle().

◆ range()

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

Definition at line 393 of file polyline.cpp.

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

Member Data Documentation

◆ s_convex

int Heed::polygon::s_convex

Definition at line 149 of file polyline.h.

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


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