Belle II Software development
Line2D Class Reference

2D line. More...

#include <Line2D.h>

Inheritance diagram for Line2D:
LineSegment2D

Public Member Functions

 Line2D (double x, double y, double vecx, double vecy)
 Constructor.
 
 ~Line2D ()
 Destructor.
 
const HepGeom::Point3D< double > & getInitialPoint () const
 Get initial point.
 
const HepGeom::Vector3D< double > & getVector () const
 Get vector.
 
int findIntersection (const Line2D &line, HepGeom::Point3D< double > *intersection) const
 Find intersection with a line.
 
int findIntersection (const Circle2D &circle, HepGeom::Point3D< double > intersections[2]) const
 Find intersections with a circle.
 
int findIntersection (const Arc2D &arc, HepGeom::Point3D< double > intersections[2]) const
 Find intersections with an arc.
 
int findIntersection (const Line2D &line, HepGeom::Point3D< double > *intersection, double t[2]) const
 Find intersection with a line.
 

Protected Member Functions

int findIntersection (const Circle2D &circle, HepGeom::Point3D< double > intersections[2], double t[2], double angles[2]) const
 Find intersections with a circle.
 
int selectIntersections (HepGeom::Point3D< double > *intersections, bool *condition, int n) const
 Select intersections.
 

Protected Attributes

HepGeom::Point3D< double > m_Point
 Initial point.
 
HepGeom::Vector3D< double > m_Vector
 Vector.
 

Detailed Description

2D line.

Equation: m_Point + m_Vector * t

Definition at line 30 of file Line2D.h.

Constructor & Destructor Documentation

◆ Line2D()

Line2D ( double  x,
double  y,
double  vecx,
double  vecy 
)

Constructor.

Parameters
[in]xInitial point X coordinate.
[in]yInitial point y coordinate.
[in]vecxVector X component.
[in]vecyVector Y component.

Definition at line 17 of file Line2D.cc.

17 :
18 m_Point(x, y, 0),
19 m_Vector(vecx, vecy, 0)
20{
21}
HepGeom::Point3D< double > m_Point
Initial point.
Definition: Line2D.h:130
HepGeom::Vector3D< double > m_Vector
Vector.
Definition: Line2D.h:133

◆ ~Line2D()

~Line2D ( )

Destructor.

Definition at line 23 of file Line2D.cc.

24{
25}

Member Function Documentation

◆ findIntersection() [1/5]

int findIntersection ( const Arc2D arc,
HepGeom::Point3D< double >  intersections[2] 
) const

Find intersections with an arc.

Parameters
[in]arcArc.
[out]intersectionsIntersections.
Returns
Number of intersections (0, 1 or 2).

Definition at line 43 of file Line2D.cc.

46{
47 int i, n;
48 double t[2], angles[2];
49 bool condition[2];
50 n = findIntersection(arc, intersections, t, angles);
51 for (i = 0; i < n; i++)
52 condition[i] = arc.angleWithinRange(angles[i]);
53 return selectIntersections(intersections, condition, n);
54}
int findIntersection(const Line2D &line, HepGeom::Point3D< double > *intersection) const
Find intersection with a line.
Definition: Line2D.cc:28
int selectIntersections(HepGeom::Point3D< double > *intersections, bool *condition, int n) const
Select intersections.
Definition: Line2D.cc:132

◆ findIntersection() [2/5]

int findIntersection ( const Circle2D circle,
HepGeom::Point3D< double >  intersections[2] 
) const

Find intersections with a circle.

Parameters
[in]circleCircle.
[out]intersectionsIntersections.
Returns
Number of intersections (0, 1 or 2).

Definition at line 35 of file Line2D.cc.

38{
39 double t[2], angles[2];
40 return findIntersection(circle, intersections, t, angles);
41}

◆ findIntersection() [3/5]

int findIntersection ( const Circle2D circle,
HepGeom::Point3D< double >  intersections[2],
double  t[2],
double  angles[2] 
) const
protected

Find intersections with a circle.

Parameters
[in]circleCircle.
[out]intersectionsIntersections.
[out]tValues of t for intersection points.
[out]anglesValues of angles for intersection points.
Returns
Number of intersections (0, 1 or 2).

Definition at line 95 of file Line2D.cc.

99{
100 int i;
101 double a, b, c, d, x0, y0;
102 const HepGeom::Point3D<double>& circleCenter = circle.getCenter();
103 x0 = m_Point.x() - circleCenter.x();
104 y0 = m_Point.y() - circleCenter.y();
105 a = m_Vector.x() * m_Vector.x() + m_Vector.y() * m_Vector.y();
106 b = 2.0 * (m_Vector.x() * x0 + m_Vector.y() * y0);
107 c = x0 * x0 + y0 * y0 - circle.getRadius() * circle.getRadius();
108 d = b * b - 4 * a * c;
109 if (d < 0)
110 return 0;
111 if (d == 0) {
112 t[0] = -b / (2.0 * a);
113 intersections[0].setX(m_Point.x() + m_Vector.x() * t[0]);
114 intersections[0].setY(m_Point.y() + m_Vector.y() * t[0]);
115 intersections[0].setZ(0);
116 angles[0] = atan2(intersections[0].y() - circleCenter.y(),
117 intersections[0].x() - circleCenter.x());
118 return 1;
119 }
120 t[0] = (-b - sqrt(d)) / (2.0 * a);
121 t[1] = (-b + sqrt(d)) / (2.0 * a);
122 for (i = 0; i < 2; i++) {
123 intersections[i].setX(m_Point.x() + m_Vector.x() * t[i]);
124 intersections[i].setY(m_Point.y() + m_Vector.y() * t[i]);
125 intersections[i].setZ(0);
126 angles[i] = atan2(intersections[i].y() - circleCenter.y(),
127 intersections[i].x() - circleCenter.x());
128 }
129 return 2;
130}
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28

◆ findIntersection() [4/5]

int findIntersection ( const Line2D line,
HepGeom::Point3D< double > *  intersection 
) const

Find intersection with a line.

Parameters
[in]lineLine.
[out]intersectionIntersection.
Returns
Number of intersections (0 or 1).

Definition at line 27 of file Line2D.cc.

30{
31 double t[2];
32 return findIntersection(line, intersection, t);
33}

◆ findIntersection() [5/5]

int findIntersection ( const Line2D line,
HepGeom::Point3D< double > *  intersection,
double  t[2] 
) const

Find intersection with a line.

Parameters
[in]lineLine.
[out]intersectionIntersection.
[out]tValues of t for intersection point (t[0] - this line, t[1] - line from argument).
Returns
Number of intersections (0 or 1).

If (*this) and line are the same line then 0 is returned.

Definition at line 65 of file Line2D.cc.

68{
69 double a1, a2, b1, b2, c1, c2, d, dt[2];
70 a1 = m_Vector.x();
71 a2 = m_Vector.y();
72 b1 = -line.getVector().x();
73 b2 = -line.getVector().y();
74 c1 = m_Point.x() - line.getInitialPoint().x();
75 c2 = m_Point.y() - line.getInitialPoint().y();
76 d = a1 * b2 - a2 * b1;
77 /* Same line (d == 0, dt[i] == 0) considered as no intersection! */
78 if (d == 0)
79 return 0;
80 dt[0] = c1 * b2 - c2 * b1;
81 dt[1] = a1 * c2 - a2 * c1;
82 t[0] = -dt[0] / d;
83 t[1] = -dt[1] / d;
84 intersection->setX(m_Point.x() + m_Vector.x() * t[0]);
85 intersection->setY(m_Point.y() + m_Vector.y() * t[0]);
86 intersection->setZ(0);
87 return 1;
88}

◆ getInitialPoint()

const HepGeom::Point3D< double > & getInitialPoint ( ) const
inline

Get initial point.

Definition at line 51 of file Line2D.h.

52 {
53 return m_Point;
54 }

◆ getVector()

const HepGeom::Vector3D< double > & getVector ( ) const
inline

Get vector.

Definition at line 59 of file Line2D.h.

60 {
61 return m_Vector;
62 }

◆ selectIntersections()

int selectIntersections ( HepGeom::Point3D< double > *  intersections,
bool *  condition,
int  n 
) const
protected

Select intersections.

Parameters
[in,out]intersectionsIntersections.
[in]conditionSelection condition.
[in]nNumber of intersections.
Returns
Number of selected intersections.

Definition at line 132 of file Line2D.cc.

134{
135 int i, j;
136 j = 0;
137 for (i = 0; i < n; i++) {
138 if (condition[i]) {
139 if (i != j)
140 intersections[j] = intersections[i];
141 j++;
142 }
143 }
144 return j;
145}

Member Data Documentation

◆ m_Point

HepGeom::Point3D<double> m_Point
protected

Initial point.

Definition at line 130 of file Line2D.h.

◆ m_Vector

HepGeom::Vector3D<double> m_Vector
protected

Vector.

Definition at line 133 of file Line2D.h.


The documentation for this class was generated from the following files: