Point A | Point B | Action |
---|---|---|
X1: 10 Y1: 16 |
X2: 15 Y2: 30 |
Remove
|
Point A | Point B | Action |
---|---|---|
X1: Y1:
|
X2: Y2:
|
Add Segment
Evaluate
Step - 0 |
Add new segments by specifying the beginning and end of the segments, once all desired segments were added, define a segment to evaluate it against all previously added segments.
The complexity of the proposed algorithm is O(N), without the need to order the segments we propose 4 steps to define all the segments that cross the segment to evaluate. But we can use a binary range search to reduce the space to evaluate, with a complexity of O(log(n) + k), where k defines the number of segments that "touch" the shadow of the evaluate segment, if this aproach is used that means more memory to store the proyection on X an Y axes.
The algorithm proposed is output sensitive, so in the case we want to evaluate all the segments against all segments the worse case is O(N^2) when all the segments are crossed and the segments are not sorted.