static Point[] GetIntersections(Segment S, ConicBezier F) { // Segment To y = kx + b format... double k = (S.to.y - S.from.y) / (S.to.x - S.from.x); if (eq(1.0 / k, eps)) // slope is infinity, or near infinity. { return(Mapping <Point, double>( F.Interpolate, Filter <double>( x => (0.0 <= x && x < 1.0 && S.CoveringPoint(F.Interpolate(x))), SolveSquare(F.from.x - S.from.x, 2.0 * (F.control.x - F.from.x), F.from.x + F.to.x - 2.0 * F.control.x)))); } else { double b = S.to.y - k * S.to.x; Point N = F.from + F.to - 2.0 * F.control; Point M = 2.0 * (F.control - F.from); Point Q = F.from; double A = k * N.x - N.y; double B = k * M.x - M.y; double C = k * Q.x - Q.y + b; return(Mapping <Point, double>( F.Interpolate, Filter <double>( x => (0.0 <= x && x <= 1.0 && S.CoveringPoint(F.Interpolate(x))), SolveSquare(A, B, C)))); } }
// ==================================================================== // Tool Functions for Shapes // ==================================================================== /// <summary> /// Intersections includes *from* points, exclude *to* points. /// </summary> static Point[] GetIntersections(ConicBezier F, Segment S) => GetIntersections(S, F);