LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
Intersections.cxx
Go to the documentation of this file.
4 
6 
7 namespace geo {
8 
9  // Functions to allow determination if two wires intersect, and if so where.
10  // This is useful information during 3D reconstruction.
11  //......................................................................
12  bool IntersectLines(double A_start_x,
13  double A_start_y,
14  double A_end_x,
15  double A_end_y,
16  double B_start_x,
17  double B_start_y,
18  double B_end_x,
19  double B_end_y,
20  double& x,
21  double& y)
22  {
23  // Equation from http://en.wikipedia.org/wiki/Line%E2%80%93line_intersection
24  // T.Yang Nov, 2014
25  // Notation: x => coordinate orthogonal to the drift direction and to the beam direction
26  // y => direction orthogonal to the previous and to beam direction
27 
28  double const denom =
29  (A_start_x - A_end_x) * (B_start_y - B_end_y) - (A_start_y - A_end_y) * (B_start_x - B_end_x);
30 
31  constexpr lar::util::RealComparisons<double> coordIs{1e-8};
32  if (coordIs.zero(denom)) return false;
33 
34  double const A = (A_start_x * A_end_y - A_start_y * A_end_x) / denom;
35  double const B = (B_start_x * B_end_y - B_start_y * B_end_x) / denom;
36 
37  x = (B_start_x - B_end_x) * A - (A_start_x - A_end_x) * B;
38  y = (B_start_y - B_end_y) * A - (A_start_y - A_end_y) * B;
39 
40  return true;
41  }
42 
43  //......................................................................
44  bool IntersectSegments(double A_start_x,
45  double A_start_y,
46  double A_end_x,
47  double A_end_y,
48  double B_start_x,
49  double B_start_y,
50  double B_end_x,
51  double B_end_y,
52  double& x,
53  double& y)
54  {
55  bool const bCross = IntersectLines(
56  A_start_x, A_start_y, A_end_x, A_end_y, B_start_x, B_start_y, B_end_x, B_end_y, x, y);
57 
58  if (bCross) {
59  mf::LogWarning("IntersectSegments") << "The segments are parallel!";
60  return false;
61  }
62 
64  A_start_x, A_start_y, A_end_x, A_end_y, B_start_x, B_start_y, B_end_x, B_end_y, x, y);
65  }
66 
67 } // namespace geo
Float_t x
Definition: compare.C:6
Functions to help with numbers.
Provides simple real number checks.
Float_t y
Definition: compare.C:6
bool IntersectSegments(double A_start_x, double A_start_y, double A_end_x, double A_end_y, double B_start_x, double B_start_y, double B_end_x, double B_end_y, double &x, double &y)
Computes the intersection between two segments on a plane.
bool PointWithinSegments(double A_start_x, double A_start_y, double A_end_x, double A_end_y, double B_start_x, double B_start_y, double B_end_x, double B_end_y, double x, double y)
Returns whether x and y are within both specified ranges (A and B).
Class for approximate comparisons.
bool IntersectLines(double A_start_x, double A_start_y, double A_end_x, double A_end_y, double B_start_x, double B_start_y, double B_end_x, double B_end_y, double &x, double &y)
Computes the intersection between two lines on a plane.
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
Float_t e
Definition: plot.C:35
Namespace collecting geometry-related classes utilities.