All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Functions
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 15 of file Polygon2D.cxx.

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

Definition at line 7 of file Polygon2D.cxx.

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

Definition at line 31 of file Polygon2D.cxx.

33 {
34 
35  //get equations for two lines
36  // [Ax,Ay]<--->[Bx,By] : y = s1*x+c1
37  // [Cx,Cy]<--->[Dx,Dy] : y = s2*x+c2
38  double s1 = (By-Ay)/(Bx-Ax);
39  double s2 = (Dy-Cy)/(Dx-Cx);
40  double c1 = By-s1*Bx;
41  double c2 = Dy-s2*Dx;
42 
43  double Xintersection = (c2-c1)/(s2-s1);
44  double Yintersection = s1 * Xintersection + c1;
45  std::pair<float,float> intersection;
46  intersection = std::make_pair(Xintersection, Yintersection);
47 
48  return intersection;
49 }
bool SegmentOverlap ( double  Ax,
double  Ay,
double  Bx,
double  By,
double  Cx,
double  Cy,
double  Dx,
double  Dy 
)

Definition at line 21 of file Polygon2D.cxx.

23 {
24 
25  bool overlap = ( (Clockwise(Ax,Ay,Cx,Cy,Dx,Dy) != Clockwise(Bx,By,Cx,Cy,Dx,Dy))
26  and (Clockwise(Ax,Ay,Bx,By,Cx,Cy) != Clockwise(Ax,Ay,Bx,By,Dx,Dy)) );
27  return overlap;
28 }
bool Clockwise(double Ax, double Ay, double Bx, double By, double Cx, double Cy)
Definition: Polygon2D.cxx:15
return match has_match and(match.match_pdg==11 or match.match_pdg==-11)