Belle II Software development
Polygon2D Class Reference

2D polygon. More...

#include <Polygon2D.h>

Public Member Functions

 Polygon2D (const HepGeom::Point3D< double > *points, int n)
 Constructor.
 
 Polygon2D (const Polygon2D &)=delete
 Copy constructor (disabled).
 
Polygon2Doperator= (const Polygon2D &)=delete
 Operator = (disabled).
 
 ~Polygon2D ()
 Destructor.
 
bool pointInside (const HepGeom::Point3D< double > &point) const
 Check if point is inside the polygon.
 
bool hasIntersection (const LineSegment2D &lineSegment) const
 Check whether polygon has an intersection with a line segment or this line segment is fully inside the polygon.
 
bool hasIntersection (const Arc2D &arc) const
 Check whether polygon has an intersection with an arc or this arc is fully inside the polygon.
 
bool hasIntersection (const Polygon2D &polygon) const
 Check whether polygon has an intersection with a polygon or one of the polygons is fully inside another polygon.
 
LineSegment2D ** getLineSegments () const
 Get line segments.
 

Private Attributes

int m_nPoints
 Number of points.
 
LineSegment2D ** m_LineSegments
 Line segments.
 

Detailed Description

2D polygon.

Definition at line 29 of file Polygon2D.h.

Constructor & Destructor Documentation

◆ Polygon2D()

Polygon2D ( const HepGeom::Point3D< double > *  points,
int  n 
)

Constructor.

Parameters
[in]pointsPoints.
[in]nNumber of points.

Definition at line 17 of file Polygon2D.cc.

17 :
18 m_nPoints(n)
19{
20 int i;
21 m_LineSegments = new LineSegment2D*[n];
22 for (i = 0; i < n; i++) {
23 if (i < n - 1)
24 m_LineSegments[i] = new LineSegment2D(points[i], points[i + 1]);
25 else
26 m_LineSegments[i] = new LineSegment2D(points[i], points[0]);
27 }
28}
int m_nPoints
Number of points.
Definition: Polygon2D.h:92
LineSegment2D ** m_LineSegments
Line segments.
Definition: Polygon2D.h:95

◆ ~Polygon2D()

~Polygon2D ( )

Destructor.

Definition at line 30 of file Polygon2D.cc.

31{
32 int i;
33 for (i = 0; i < m_nPoints; i++)
34 delete m_LineSegments[i];
35 delete[] m_LineSegments;
36}

Member Function Documentation

◆ getLineSegments()

LineSegment2D ** getLineSegments ( ) const
inline

Get line segments.

Definition at line 84 of file Polygon2D.h.

85 {
86 return m_LineSegments;
87 }

◆ hasIntersection() [1/3]

bool hasIntersection ( const Arc2D arc) const

Check whether polygon has an intersection with an arc or this arc is fully inside the polygon.

Parameters
[in]arcArc.

Definition at line 76 of file Polygon2D.cc.

77{
78 int i;
79 HepGeom::Point3D<double> intersections[2];
80 for (i = 0; i < m_nPoints; i++) {
81 if (m_LineSegments[i]->findIntersection(arc, intersections) > 0)
82 return true;
83 }
84 if (pointInside(arc.getInitialPoint()))
85 return true;
86 return false;
87}
bool pointInside(const HepGeom::Point3D< double > &point) const
Check if point is inside the polygon.
Definition: Polygon2D.cc:38

◆ hasIntersection() [2/3]

bool hasIntersection ( const LineSegment2D lineSegment) const

Check whether polygon has an intersection with a line segment or this line segment is fully inside the polygon.

Parameters
[in]lineSegmentLine segment.

Definition at line 63 of file Polygon2D.cc.

64{
65 int i;
66 HepGeom::Point3D<double> intersection;
67 for (i = 0; i < m_nPoints; i++) {
68 if (m_LineSegments[i]->findIntersection(lineSegment, &intersection) > 0)
69 return true;
70 }
71 if (pointInside(lineSegment.getInitialPoint()))
72 return true;
73 return false;
74}

◆ hasIntersection() [3/3]

bool hasIntersection ( const Polygon2D polygon) const

Check whether polygon has an intersection with a polygon or one of the polygons is fully inside another polygon.

Parameters
[in]polygonPolygon.

Definition at line 89 of file Polygon2D.cc.

90{
91 int i;
92 for (i = 0; i < m_nPoints; i++) {
93 if (polygon.hasIntersection(*m_LineSegments[i]))
94 return true;
95 }
96 if (pointInside(polygon.getLineSegments()[0]->getInitialPoint()) ||
97 polygon.pointInside(m_LineSegments[0]->getInitialPoint()))
98 return true;
99 return false;
100}
const HepGeom::Point3D< double > & getInitialPoint() const
Get initial point.
Definition: Line2D.h:51

◆ pointInside()

bool pointInside ( const HepGeom::Point3D< double > &  point) const

Check if point is inside the polygon.

Definition at line 38 of file Polygon2D.cc.

39{
40 int i, n, nIntersections;
41 double angle, t[2];
42 HepGeom::Point3D<double> intersection;
43new_line: {
44 nIntersections = 0;
45 angle = gRandom->Uniform(0., 2.0 * M_PI);
46 Line2D line(point.x(), point.y(), cos(angle), sin(angle));
47 for (i = 0; i < m_nPoints; i++) {
48 n = m_LineSegments[i]->Line2D::findIntersection(line, &intersection, t);
49 if (n == 0)
50 continue;
51 /* Line goes through vertex, need to generate another line. */
52 if (t[0] == 0 || t[0] == 1)
53 goto new_line;
54 if (t[0] > 0 && t[0] < 1 && t[1] > 0)
55 nIntersections++;
56 }
57 }
58 if (nIntersections % 2 == 1)
59 return true;
60 return false;
61}

Member Data Documentation

◆ m_LineSegments

LineSegment2D** m_LineSegments
private

Line segments.

Definition at line 95 of file Polygon2D.h.

◆ m_nPoints

int m_nPoints
private

Number of points.

Definition at line 92 of file Polygon2D.h.


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