Belle II Software  release-08-01-10
LineSegment2D.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 /* Own header. */
10 #include <klm/eklm/geometry/LineSegment2D.h>
11 
12 using namespace Belle2;
13 
15  const HepGeom::Point3D<double>& point2) :
16  Line2D(point1.x(), point1.y(),
17  point2.x() - point1.x(), point2.y() - point1.y())
18 {
19 }
20 
22 {
23 }
24 
26 findIntersection(const Line2D& line,
27  HepGeom::Point3D<double>* intersection) const
28 {
29  int n;
30  double t[2];
31  bool condition;
32  n = Line2D::findIntersection(line, intersection, t);
33  if (n == 0)
34  return 0;
35  condition = tWithinRange(t[0]);
36  return selectIntersections(intersection, &condition, 1);
37 }
38 
39 
41 findIntersection(const LineSegment2D& lineSegment,
42  HepGeom::Point3D<double>* intersection) const
43 {
44  int n;
45  double t[2];
46  bool condition;
47  n = Line2D::findIntersection(lineSegment, intersection, t);
48  if (n == 0)
49  return 0;
50  condition = tWithinRange(t[0]) && lineSegment.tWithinRange(t[1]);
51  return selectIntersections(intersection, &condition, 1);
52 }
53 
55 findIntersection(const Circle2D& circle,
56  HepGeom::Point3D<double> intersections[2]) const
57 {
58  int i, n;
59  double t[2], angles[2];
60  bool condition[2];
61  n = Line2D::findIntersection(circle, intersections, t, angles);
62  for (i = 0; i < n; i++)
63  condition[i] = tWithinRange(t[i]);
64  return selectIntersections(intersections, condition, n);
65 }
66 
68 findIntersection(const Arc2D& arc,
69  HepGeom::Point3D<double> intersections[2]) const
70 {
71  int i, n;
72  double t[2], angles[2];
73  bool condition[2];
74  n = Line2D::findIntersection(arc, intersections, t, angles);
75  for (i = 0; i < n; i++)
76  condition[i] = tWithinRange(t[i]) && arc.angleWithinRange(angles[i]);
77  return selectIntersections(intersections, condition, n);
78 }
79 
81 {
82  return (t >= 0 && t <= 1);
83 }
84 
bool angleWithinRange(double angle) const
Check if angle is within the arc.
Definition: Arc2D.cc:26
int findIntersection(const Line2D &line, HepGeom::Point3D< double > *intersection) const
Find intersection with a line.
Definition: Line2D.cc:28
int findIntersection(const Line2D &line, HepGeom::Point3D< double > *intersection) const
Find intersection with a line.
bool tWithinRange(double t) const
Check if t is within the line segment (0 <= t <= 1).
LineSegment2D(const HepGeom::Point3D< double > &point1, const HepGeom::Point3D< double > &point2)
Constructor.
Abstract base class for different kinds of events.