#include "Polygon2D.h"
|
| Polygon2D () |
|
| Polygon2D (const std::vector< std::pair< float, float >> &points) |
|
| Polygon2D (const Polygon2D &poly1, const Polygon2D &poly2) |
|
unsigned int | Size () const |
| Create Intersection Polygon. More...
|
|
const std::pair< float, float > & | Point (unsigned int p) const |
|
std::pair< float, float > | Project (const std::pair< float, float > &, float) const |
|
float | Area () const |
|
float | Perimeter () const |
|
bool | Overlap (float slope, const Polygon2D &poly2, const std::pair< float, float > &origin) const |
|
bool | PolyOverlap (const Polygon2D &poly2) const |
|
bool | PolyOverlapSegments (const Polygon2D &poly2) const |
|
bool | PointInside (const std::pair< float, float > &point) const |
|
bool | Contained (const Polygon2D &poly2) const |
|
void | UntanglePolygon () |
| check if poly2 is inside poly1 More...
|
|
|
std::vector< std::pair< float, float > > | vertices |
|
Definition at line 32 of file Polygon2D.h.
Polygon2D::Polygon2D |
( |
const std::vector< std::pair< float, float >> & |
points | ) |
|
|
inline |
Definition at line 63 of file Polygon2D.cxx.
References GetIntersection(), Point(), PointInside(), PolyOverlap(), SegmentOverlap(), Size(), and vertices.
68 std::vector<std::pair<float, float>> nullpoint;
80 std::vector<std::pair<float, float>> IntersectionPoints;
82 for (
unsigned int p1 = 0; p1 < poly1.
Size(); p1++) {
86 for (
unsigned int p2 = 0; p2 < poly2.
Size(); p2++) {
91 for (
unsigned int i = 0; i < poly1.
Size(); i++) {
92 for (
unsigned int j = 0; j < poly2.
Size(); j++) {
94 poly1.
Point(i).second,
95 poly1.
Point(i + 1).first,
96 poly1.
Point(i + 1).second,
98 poly2.
Point(j).second,
99 poly2.
Point(j + 1).first,
100 poly2.
Point(j + 1).second))
103 poly1.
Point(i).second,
104 poly1.
Point(i + 1).first,
105 poly1.
Point(i + 1).second,
106 poly2.
Point(j).first,
107 poly2.
Point(j).second,
108 poly2.
Point(j + 1).first,
109 poly2.
Point(j + 1).second));
const std::pair< float, float > & Point(unsigned int p) const
unsigned int Size() const
Create Intersection Polygon.
std::vector< std::pair< float, float > > vertices
std::pair< float, float > GetIntersection(double Ax, double Ay, double Bx, double By, double Cx, double Cy, double Dx, double Dy)
bool SegmentOverlap(double Ax, double Ay, double Bx, double By, double Cx, double Cy, double Dx, double Dy)
bool PointInside(const std::pair< float, float > &point) const
bool PolyOverlap(const Polygon2D &poly2) const
float Polygon2D::Area |
( |
| ) |
const |
Definition at line 118 of file Polygon2D.cxx.
References vertices.
Referenced by Size().
123 for (
unsigned int i = 0; i <
vertices.size(); i++) {
131 if (area < 0.0) area = -area;
std::vector< std::pair< float, float > > vertices
second_as<> second
Type of time stored in seconds, in double precision.
bool Polygon2D::Contained |
( |
const Polygon2D & |
poly2 | ) |
const |
Definition at line 296 of file Polygon2D.cxx.
References Point(), PointInside(), and Size().
Referenced by PolyOverlapSegments(), and Size().
301 for (
unsigned int i = 0; i < poly2.
Size(); i++) {
const std::pair< float, float > & Point(unsigned int p) const
unsigned int Size() const
Create Intersection Polygon.
bool PointInside(const std::pair< float, float > &point) const
bool Polygon2D::Overlap |
( |
float |
slope, |
|
|
const Polygon2D & |
poly2, |
|
|
const std::pair< float, float > & |
origin |
|
) |
| const |
Definition at line 199 of file Polygon2D.cxx.
References Project().
Referenced by PolyOverlap(), and Size().
204 float theta = tan(slope);
206 std::pair<float, float> range1 = this->
Project(
origin, theta);
207 std::pair<float, float> range2 = poly2.
Project(
origin, theta);
211 if ((((range1.first <= range2.second) and (range1.first >= range2.first)) or
212 ((range1.second <= range2.second) and (range1.second >= range2.first))) or
213 (((range2.first <= range1.second) and (range2.first >= range1.first)) or
214 ((range2.second <= range1.second) and (range2.second >= range1.first))))
std::pair< float, float > Project(const std::pair< float, float > &, float) const
constexpr Point origin()
Returns a origin position with a point of the specified type.
float Polygon2D::Perimeter |
( |
| ) |
const |
Definition at line 136 of file Polygon2D.cxx.
References vertices.
Referenced by Size().
139 float perimeter = 0.;
141 for (
unsigned int i = 0; i <
vertices.size(); i++) {
154 return sqrt(perimeter);
std::vector< std::pair< float, float > > vertices
const std::pair< float, float > & Polygon2D::Point |
( |
unsigned int |
p | ) |
const |
bool Polygon2D::PointInside |
( |
const std::pair< float, float > & |
point | ) |
const |
Definition at line 271 of file Polygon2D.cxx.
References Point(), SegmentOverlap(), and Size().
Referenced by cmtool::CBAlgoCenterOfMass::Bool(), cmtool::CBAlgoCenterOfMassSmall::Bool(), Contained(), Polygon2D(), and Size().
277 int intersections = 0;
278 for (
unsigned int i = 0; i < this->
Size(); i++) {
281 this->
Point(i + 1).first,
282 this->
Point(i + 1).second,
289 if ((intersections % 2) == 0)
const std::pair< float, float > & Point(unsigned int p) const
unsigned int Size() const
Create Intersection Polygon.
bool SegmentOverlap(double Ax, double Ay, double Bx, double By, double Cx, double Cy, double Dx, double Dy)
second_as<> second
Type of time stored in seconds, in double precision.
bool Polygon2D::PolyOverlap |
( |
const Polygon2D & |
poly2 | ) |
const |
Definition at line 221 of file Polygon2D.cxx.
References FindSlope(), Overlap(), Point(), and Size().
Referenced by Polygon2D(), and Size().
227 for (
unsigned int i = 0; i < this->
Size(); i++) {
234 if (!(this->
Overlap(slope, poly2, this->
Point(i))))
return false;
238 for (
unsigned int i = 0; i < poly2.
Size(); i++) {
241 if (!(poly2.
Overlap(slope, *
this, poly2.
Point(i))))
return false;
const std::pair< float, float > & Point(unsigned int p) const
unsigned int Size() const
Create Intersection Polygon.
bool Overlap(float slope, const Polygon2D &poly2, const std::pair< float, float > &origin) const
float FindSlope(const std::pair< float, float > &p1, const std::pair< float, float > &p2)
bool Polygon2D::PolyOverlapSegments |
( |
const Polygon2D & |
poly2 | ) |
const |
Definition at line 247 of file Polygon2D.cxx.
References Contained(), Point(), SegmentOverlap(), and Size().
Referenced by Size().
253 for (
unsigned int i = 0; i < this->
Size(); i++) {
254 for (
unsigned int j = 0; j < poly2.
Size(); j++) {
257 this->
Point(i + 1).first,
258 this->
Point(i + 1).second,
259 poly2.
Point(j).first,
260 poly2.
Point(j).second,
261 poly2.
Point(j + 1).first,
262 poly2.
Point(j + 1).second)) {
bool Contained(const Polygon2D &poly2) const
const std::pair< float, float > & Point(unsigned int p) const
unsigned int Size() const
Create Intersection Polygon.
bool SegmentOverlap(double Ax, double Ay, double Bx, double By, double Cx, double Cy, double Dx, double Dy)
second_as<> second
Type of time stored in seconds, in double precision.
std::pair< float, float > Polygon2D::Project |
( |
const std::pair< float, float > & |
p, |
|
|
float |
theta |
|
) |
| const |
Definition at line 175 of file Polygon2D.cxx.
References vertices.
Referenced by Overlap(), and Size().
178 std::pair<float, float> range(10000, 0);
179 std::pair<float, float> ptmp;
181 for (
unsigned int i = 0; i <
vertices.size(); i++) {
190 float xnew = (ptmp.first) * cos(theta) + (ptmp.second) * sin(theta);
192 if (xnew < range.first) range.first = xnew;
193 if (xnew > range.second) range.second = xnew;
std::vector< std::pair< float, float > > vertices
second_as<> second
Type of time stored in seconds, in double precision.
unsigned int Polygon2D::Size |
( |
| ) |
const |
|
inline |
Create Intersection Polygon.
Definition at line 41 of file Polygon2D.h.
References Area(), Contained(), geo::origin(), Overlap(), Perimeter(), Point(), PointInside(), PolyOverlap(), PolyOverlapSegments(), Project(), and UntanglePolygon().
Referenced by Contained(), PointInside(), Polygon2D(), PolyOverlap(), and PolyOverlapSegments().
std::vector< std::pair< float, float > > vertices
void Polygon2D::UntanglePolygon |
( |
| ) |
|
check if poly2 is inside poly1
Definition at line 309 of file Polygon2D.cxx.
References SegmentOverlap(), tmp, and vertices.
Referenced by Size().
313 for (
unsigned int i = 0; i <
vertices.size() - 1; i++) {
316 double Bx =
vertices.at(i + 1).first;
317 double By =
vertices.at(i + 1).second;
319 for (
unsigned int j = i + 2; j <
vertices.size() - 1; j++) {
326 double Dx =
vertices.at(j + 1).first;
327 double Dy =
vertices.at(j + 1).second;
std::vector< std::pair< float, float > > vertices
bool SegmentOverlap(double Ax, double Ay, double Bx, double By, double Cx, double Cy, double Dx, double Dy)
void UntanglePolygon()
check if poly2 is inside poly1
std::vector<std::pair<float, float> > Polygon2D::vertices |
|
private |
The documentation for this class was generated from the following files:
- larreco/v09_25_00/source/larreco/RecoAlg/ClusterRecoUtil/Polygon2D.h
- larreco/v09_25_00/source/larreco/RecoAlg/ClusterRecoUtil/Polygon2D.cxx