10#include <klm/eklm/geometry/Line2D.h>
13#include <klm/eklm/geometry/Circle2D.h>
19 m_Vector(vecx, vecy, 0)
32 return findIntersection(line, intersection, t);
39 double t[2], angles[2];
40 return findIntersection(circle, intersections, t, angles);
48 double t[2], angles[2];
50 n = findIntersection(arc, intersections, t, angles);
51 for (i = 0; i < n; i++)
53 return selectIntersections(intersections, condition, n);
69 double a1, a2, b1, b2, c1, c2, d, dt[2];
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;
80 dt[0] = c1 * b2 - c2 * b1;
81 dt[1] = a1 * c2 - a2 * c1;
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);
98 double t[2],
double angles[2])
const
101 double a, b, c, d, x0, y0;
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);
108 d = b * b - 4 * a * c;
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());
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());
133 bool* condition,
int n)
const
137 for (i = 0; i < n; i++) {
140 intersections[j] = intersections[i];
bool angleWithinRange(double angle) const
Check if angle is within the arc.
const HepGeom::Point3D< double > & getCenter() const
Get center.
double getRadius() const
Get radius.
int findIntersection(const Line2D &line, HepGeom::Point3D< double > *intersection) const
Find intersection with a line.
int selectIntersections(HepGeom::Point3D< double > *intersections, bool *condition, int n) const
Select intersections.
Line2D(double x, double y, double vecx, double vecy)
Constructor.
double sqrt(double a)
sqrt for double
Abstract base class for different kinds of events.