22 const Eigen::Vector2d &p1,
23 const Eigen::Vector2d &p2,
24 std::vector<Eigen::Vector2d> &inters) {
25 double dx, dy, A, B, C,
det, t;
30 A = dx * dx + dy * dy;
31 B = 2 * (dx * (p1.x() - cx) + dy * (p1.y() - cy));
32 C = (p1.x() - cx) * (p1.x() - cx) + (p1.y() - cy) * (p1.y() - cy) -
35 det = B * B - 4 * A * C;
36 if ((A <= 0.0000001) || (det < 0)) {
39 }
else if (det == 0) {
42 inters.push_back(Eigen::Vector2d(p1.x() + t * dx, p1.y() + t * dy));
46 t = (double)((-B + sqrt(det)) / (2 * A));
47 inters.push_back(Eigen::Vector2d(p1.x() + t * dx, p1.y() + t * dy));
49 t = (double)((-B - sqrt(det)) / (2 * A));
50 inters.push_back(Eigen::Vector2d(p1.x() + t * dx, p1.y() + t * dy));
70 if (q.
x <= max(p.
x, r.
x) && q.
x >= min(p.
x, r.
x) && q.
y <= max(p.
y, r.
y) &&
85 double val = (q.
y - p.
y) * (r.
x - q.
x) - (q.
x - p.
x) * (r.
y - q.
y);
87 if (val == 0)
return 0;
89 return (val > 0) ? 1 : 2;
92 inline double det(
double a,
double b,
double c,
double d) {
100 double &ixOut,
double &iyOut)
104 double detL1 =
det(x1, y1, x2, y2);
105 double detL2 =
det(x3, y3, x4, y4);
106 double x1mx2 = x1 - x2;
107 double x3mx4 = x3 - x4;
108 double y1my2 = y1 - y2;
109 double y3my4 = y3 - y4;
111 double xnom =
det(detL1, x1mx2, detL2, x3mx4);
112 double ynom =
det(detL1, y1my2, detL2, y3my4);
113 double denom =
det(x1mx2, y1my2, x3mx4, y3my4);
121 ixOut = xnom / denom;
122 iyOut = ynom / denom;
123 if (!isfinite(ixOut) || !isfinite(iyOut))
133 std::vector<Point> &inters) {
142 if (o1 != o2 && o3 != o4) {
148 intersection1.
x = int_x;
149 intersection1.
y = int_y;
150 inters.push_back(intersection1);
159 if (o1 == 0 && o2 == 0) {
166 inters.push_back(p2);
168 if (outnum == 2)
return true;
172 inters.push_back(q2);
175 if (outnum == 2)
return true;
181 inters.push_back(p1);
184 if (outnum == 2)
return true;
188 inters.push_back(q1);
198 inters.push_back(p2);
204 inters.push_back(q2);
210 inters.push_back(p1);
216 inters.push_back(q1);
bool lineLineIntersect(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double &ixOut, double &iyOut)
void RaiseRaytraceError(const char *)
int findLineCircleIntersections(double cx, double cy, double radius, const Eigen::Vector2d &p1, const Eigen::Vector2d &p2, std::vector< Eigen::Vector2d > &inters)
double det(double a, double b, double c, double d)
void RaytraceDebugOutput(const char *)
bool onSegment(Point p, Point q, Point r)
bool doIntersect(Point p1, Point q1, Point p2, Point q2, std::vector< Point > &inters)
int orientation(Point p, Point q, Point r)