Belle II Software development
DedxLine Class Reference

A class to hold the endpoints and slope of a line. More...

#include <LineHelper.h>

Public Member Functions

 DedxLine ()
 A line is definied either by a point and a slope, or by endpoints.
 
 DedxLine (const DedxPoint &p, const double slope)
 Construct a DedxLine from the given DedxPoint and slope.
 
 DedxLine (const DedxPoint &p1, const DedxPoint &p2)
 Construct a DedxLine from two DedxPoints.
 
double getSlope () const
 Helper function to return the slope.
 
DedxPoint intersection (const DedxLine &l)
 Find the intersection of this and another line.
 
bool isVertical () const
 The m_vertical flag is used for the special case of a vertical line.
 
void setVertical ()
 Mark this DedxLine as being vertical.
 

Private Attributes

DedxPoint m_p1
 First endpoint.
 
DedxPoint m_p2
 Second endpoint.
 
double m_m
 Slope of the line.
 
int m_vertical
 If the line is vertical, this is set to true.
 

Detailed Description

A class to hold the endpoints and slope of a line.

This class is useful in determining the path length of a track through a CDC cell.

Definition at line 83 of file LineHelper.h.

Constructor & Destructor Documentation

◆ DedxLine() [1/3]

DedxLine ( )
inline

A line is definied either by a point and a slope, or by endpoints.

If a single point is given, both endpoints are given by the same point (length = 0). Default constructor

Definition at line 92 of file LineHelper.h.

92: m_m(0), m_vertical(false) {}
int m_vertical
If the line is vertical, this is set to true.
Definition: LineHelper.h:177
double m_m
Slope of the line.
Definition: LineHelper.h:176

◆ DedxLine() [2/3]

DedxLine ( const DedxPoint p,
const double  slope 
)
inline

Construct a DedxLine from the given DedxPoint and slope.

Definition at line 95 of file LineHelper.h.

95: m_p1(p), m_p2(p), m_m(slope), m_vertical(false) {}
DedxPoint m_p2
Second endpoint.
Definition: LineHelper.h:175
DedxPoint m_p1
First endpoint.
Definition: LineHelper.h:174

◆ DedxLine() [3/3]

DedxLine ( const DedxPoint p1,
const DedxPoint p2 
)
inline

Construct a DedxLine from two DedxPoints.

Definition at line 98 of file LineHelper.h.

98 : m_p1(p1), m_p2(p2), m_vertical(false)
99 {
100 //check if the line is vertical (set vertical flag if it is)
101 if (p1.getX() == p2.getX()) {
102 m_m = -10000.0;
103 m_vertical = true;
104 } else
105 m_m = (p1.getY() - p2.getY()) / (p1.getX() - p2.getX());
106 }

Member Function Documentation

◆ getSlope()

double getSlope ( ) const
inline

Helper function to return the slope.

Definition at line 109 of file LineHelper.h.

109{ return m_m; }

◆ intersection()

DedxPoint intersection ( const DedxLine l)
inline

Find the intersection of this and another line.

Definition at line 112 of file LineHelper.h.

113 {
114 double x, y;
115 DedxPoint intP;
116
117 // First check if the lines will intersect.
118 // Also check for special cases of horizontal or
119 // vertical lines.
120 if (m_m == l.m_m) {
121 B2WARNING("Lines are parallel, will not intersect...");
122 intP.setInvalid();
123 intP.setPoint(0, 0);
124 return intP;
125 } else if (m_m == 0.0) {
126 y = m_p1.getY();
127 x = (y - l.m_p1.getY()) / l.m_m + l.m_p1.getX();
128 } else if (l.m_m == 0.0) {
129 y = l.m_p1.getY();
130 x = (y - m_p1.getY()) / m_m + m_p1.getX();
131 } else if (m_vertical) {
132 x = m_p1.getX();
133 y = l.m_p1.getY() + l.m_m * (x - l.m_p1.getX());
134 } else if (l.isVertical()) {
135 x = l.m_p1.getX();
136 y = m_p1.getY() + m_m * (x - m_p1.getX());
137 } else {
138 x = ((l.m_p1.getY() - l.m_m * l.m_p1.getX()) - (m_p1.getY() - m_m * m_p1.getX())) / (m_m - l.m_m);
139 y = m_p1.getY() + m_m * (x - m_p1.getX());
140 }
141
142 // This is the point of intersection
143 intP.setPoint(x, y);
144
145 // Check if the point falls outside the endpoints of the line.
146 // This is useful for calculating the track length (dx).
147 if ((x > m_p1.getX() && x > m_p2.getX()) ||
148 (x < m_p1.getX() && x < m_p2.getX()))
149 intP.setInvalid();
150 if ((y > m_p1.getY() && y > m_p2.getY()) ||
151 (y < m_p1.getY() && y < m_p2.getY()))
152 intP.setInvalid();
153
154 // Check if the DedxLine was made from a point and make sure the
155 // point is not outside the cell
156 if (l.m_p1.getX() == l.m_p2.getX() && l.m_p1.getY() == l.m_p2.getY() &&
157 ((l.m_p1.getX() > m_p1.getX() && l.m_p1.getX() > m_p2.getX()) ||
158 (l.m_p1.getX() < m_p1.getX() && l.m_p1.getX() < m_p2.getX())) &&
159 ((l.m_p1.getY() > m_p1.getY() && l.m_p1.getY() > m_p2.getY()) ||
160 (l.m_p1.getY() < m_p1.getY() && l.m_p1.getY() < m_p2.getY())))
161 intP.setInvalid();
162
163 return intP;
164 }
double getX() const
Helper function to return the x-coordinates of a DedxPoint.
Definition: LineHelper.h:40
double getY() const
Helper function to return the y-coordinates of a DedxPoint.
Definition: LineHelper.h:43

◆ isVertical()

bool isVertical ( ) const
inline

The m_vertical flag is used for the special case of a vertical line.

Definition at line 167 of file LineHelper.h.

167{ return m_vertical; }

◆ setVertical()

void setVertical ( )
inline

Mark this DedxLine as being vertical.

Definition at line 170 of file LineHelper.h.

170{ m_vertical = true; }

Member Data Documentation

◆ m_m

double m_m
private

Slope of the line.

Definition at line 176 of file LineHelper.h.

◆ m_p1

DedxPoint m_p1
private

First endpoint.

Definition at line 174 of file LineHelper.h.

◆ m_p2

DedxPoint m_p2
private

Second endpoint.

Definition at line 175 of file LineHelper.h.

◆ m_vertical

int m_vertical
private

If the line is vertical, this is set to true.

Definition at line 177 of file LineHelper.h.


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