Here is my problem: I have two very large lists of intervals (stored as many couples in the form {{"start point", "end point"}, ..., {"start point", "end point"}
), and I want the result of the intersection of those lists.
Here is an example :
intervalsA = {{1, 2}, {3, 4}, {5, 7}, {8, 8.5}};
intervalsB = {{1.5, 3.5}, {4.1, 6}, {9, 10}};
The expected result is: overlap = {{1.5, 2}, {3, 3.5}, {5, 6}};
I tried using Interval
, IntervalUnion
and IntervalIntersection
, but nothing worked. The only working method that I found uses Piecewise
functions where each interval is set as 1. By multiplying the two piecewise functions, I have something similar to the intersection, but the solution is very inefficient.
I hope I am clear and precise enough.
List @@ IntervalIntersection[Interval @@ intervalsA, Interval @@ intervalsB]
-->{{1.5, 2}, {3, 3.5}, {5, 6}}
$\endgroup$ – alancalvitti Jul 28 '14 at 14:12