LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
Polygon2D.cxx File Reference
#include "Polygon2D.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 12 of file Polygon2D.cxx.

Referenced by SegmentOverlap().

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

Definition at line 4 of file Polygon2D.cxx.

Referenced by Polygon2D::PolyOverlap().

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

Definition at line 28 of file Polygon2D.cxx.

References c1, and c2.

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

30 {
31 
32  //get equations for two lines
33  // [Ax,Ay]<--->[Bx,By] : y = s1*x+c1
34  // [Cx,Cy]<--->[Dx,Dy] : y = s2*x+c2
35  double s1 = (By-Ay)/(Bx-Ax);
36  double s2 = (Dy-Cy)/(Dx-Cx);
37  double c1 = By-s1*Bx;
38  double c2 = Dy-s2*Dx;
39 
40  double Xintersection = (c2-c1)/(s2-s1);
41  double Yintersection = s1 * Xintersection + c1;
42  std::pair<float,float> intersection;
43  intersection = std::make_pair(Xintersection, Yintersection);
44 
45  return intersection;
46 }
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 18 of file Polygon2D.cxx.

References Clockwise().

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

20 {
21 
22  bool overlap = ( (Clockwise(Ax,Ay,Cx,Cy,Dx,Dy) != Clockwise(Bx,By,Cx,Cy,Dx,Dy))
23  and (Clockwise(Ax,Ay,Bx,By,Cx,Cy) != Clockwise(Ax,Ay,Bx,By,Dx,Dy)) );
24  return overlap;
25 }
bool Clockwise(double Ax, double Ay, double Bx, double By, double Cx, double Cy)
Definition: Polygon2D.cxx:12