LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
Polygon2D.cxx File Reference
#include "Polygon2D.h"
#include <iostream>
#include <math.h>

Go to the source code of this file.

Functions

float FindSlope (const std::pair< float, float > &p1, const std::pair< float, float > &p2)
 
bool Clockwise (double Ax, double Ay, double Bx, double By, double Cx, double Cy)
 
bool SegmentOverlap (double Ax, double Ay, double Bx, double By, double Cx, double Cy, double Dx, double Dy)
 
std::pair< float, float > GetIntersection (double Ax, double Ay, double Bx, double By, double Cx, double Cy, double Dx, double Dy)
 

Function Documentation

bool Clockwise ( double  Ax,
double  Ay,
double  Bx,
double  By,
double  Cx,
double  Cy 
)

Definition at line 14 of file Polygon2D.cxx.

Referenced by util::GeometryUtilities::Get2DPointProjection(), and SegmentOverlap().

15 {
16  return (Cy - Ay) * (Bx - Ax) > (By - Ay) * (Cx - Ax);
17 }
float FindSlope ( const std::pair< float, float > &  p1,
const std::pair< float, float > &  p2 
)

Definition at line 7 of file Polygon2D.cxx.

Referenced by Polygon2D::PolyOverlap().

8 {
9  float slope = (p2.second - p1.second) / (p2.first - p1.first);
10  return slope;
11 }
std::pair<float, float> GetIntersection ( double  Ax,
double  Ay,
double  Bx,
double  By,
double  Cx,
double  Cy,
double  Dx,
double  Dy 
)

Definition at line 36 of file Polygon2D.cxx.

References c1, and c2.

Referenced by lar_content::LArPointingClusterHelper::GetAverageDirection(), and Polygon2D::Polygon2D().

44 {
45 
46  //get equations for two lines
47  // [Ax,Ay]<--->[Bx,By] : y = s1*x+c1
48  // [Cx,Cy]<--->[Dx,Dy] : y = s2*x+c2
49  double s1 = (By - Ay) / (Bx - Ax);
50  double s2 = (Dy - Cy) / (Dx - Cx);
51  double c1 = By - s1 * Bx;
52  double c2 = Dy - s2 * Dx;
53 
54  double Xintersection = (c2 - c1) / (s2 - s1);
55  double Yintersection = s1 * Xintersection + c1;
56  std::pair<float, float> intersection;
57  intersection = std::make_pair(Xintersection, Yintersection);
58 
59  return intersection;
60 }
TCanvas * c1
Definition: plotHisto.C:7
TCanvas * c2
Definition: plot_hist.C:75
bool SegmentOverlap ( double  Ax,
double  Ay,
double  Bx,
double  By,
double  Cx,
double  Cy,
double  Dx,
double  Dy 
)

Definition at line 20 of file Polygon2D.cxx.

References Clockwise().

Referenced by Polygon2D::PointInside(), Polygon2D::Polygon2D(), Polygon2D::PolyOverlapSegments(), and Polygon2D::UntanglePolygon().

28 {
29 
30  bool overlap = ((Clockwise(Ax, Ay, Cx, Cy, Dx, Dy) != Clockwise(Bx, By, Cx, Cy, Dx, Dy)) and
31  (Clockwise(Ax, Ay, Bx, By, Cx, Cy) != Clockwise(Ax, Ay, Bx, By, Dx, Dy)));
32  return overlap;
33 }
bool Clockwise(double Ax, double Ay, double Bx, double By, double Cx, double Cy)
Definition: Polygon2D.cxx:14