What Are We Trying to Compute?
If someone gives you several line segments and asks where they intersect, what would you do? A direct approach is to take two segments, check whether they share any part, and then move on to another pair until every pair of distinct inputs has been checked.
This approach is easy to think of. Before looking for a method that does less work, however, we need to clarify two things: what do we check each time, and what result should we keep?
This is Chapter 1 of the Bentley–Ottmann segment intersection series. We first establish the problem and a baseline method. The next chapter studies how a sweep line can reduce the number of segment pairs that need attention.
Each Input Has Its Own Identity
A segment can be described by two endpoints. For example, the segment with endpoints and is the part of the horizontal axis from to .
The segments we discuss include both endpoints. Such a segment is called a “closed segment.” Thus, both and lie on this segment. A line extends indefinitely in both directions, but a segment has a limited extent: lies on the line extending this segment, but not on the segment itself. To review how an equation and coordinate bounds work together to describe a segment, see Writing a Line Equation from Two Endpoints.
The two endpoints may also be the same. If both are , the input contains only the point and has length . We accept inputs like this too.
Now number the inputs: input , input , input , and so on. A number distinguishes one input from another; it does not describe the segment's length or location.
Suppose we have the following three inputs. The figures label them , , and ; the subscript is the input number:
| Input number | Endpoints |
|---|---|
| and | |
| and | |
| and |
They occupy exactly the same geometric location. The third input merely lists its endpoints in reverse order, which does not change the points it contains. Nevertheless, these are three inputs. We must not silently merge them into one just because their drawings coincide.
The three panels show inputs , , and in order. When space is limited, they wrap onto another row; read from left to right and then top to bottom. Every panel retains its original size and uses the same coordinate range and scale. Coincident segments have not been shifted apart. Although the third input lists its endpoints in reverse order, its segment is unchanged. The arrow below each panel shows only the order in which the endpoints are written; it does not give the segment a direction. In the figures, denotes the origin, axis arrows indicate positive directions, and filled endpoint circles show that the endpoints are included.
We use “input pair and ” to mean the two inputs numbered and . This is the same pair as “input pair and ,” because reversing the order of checking does not change their common part. This is called an “unordered input pair.” We choose two distinct inputs and never check an input against itself.
What Can Two Segments Have in Common?
All points belonging to both segments together form their “intersection.” If they have no common point, their intersection is empty.
Fix a segment from to . Every point on it satisfies , and its horizontal coordinate ranges from to , including both ends. In each example below, choose one other segment and compare it with alone.
In the figures, labels the other input, and denotes the intersection of the two inputs. The symbol is read as “intersection.” When there is no common point, we denote the empty intersection by .
No Common Point: An Empty Intersection
Let the other segment run from to . All its points satisfy , whereas all points on satisfy . A point's vertical coordinate cannot be both and , so the segments have no common point.
We have checked this input pair, but it produces no intersection result record.
Here and in the groups below, the three panels are ordered as “input A, other input B, complete intersection.” Continue in that order if the panels wrap. All use the same coordinate range and scale. Coordinates are shown beside endpoints. The third panel shows only the intersection, without drawing the inputs again; an empty intersection is marked . Thin gray lines are coordinate axes, not parts of the inputs or results.
Exactly One Common Point: A Point Intersection
Replace the other segment with the vertical segment from to . Every point on it satisfies . A common point must also lie on , so its vertical coordinate must be .
These two conditions leave only . Its horizontal coordinate is between and , and its vertical coordinate is between and , so it really lies on both segments. Their intersection is this one point.
Touching at an endpoint also counts as intersecting. For example, replace the other segment with the horizontal segment from to . A common point's horizontal coordinate can be neither greater than nor less than , so it must equal . Both segments include this endpoint, making their intersection .
Zero-length inputs follow the same definition. If the other input contains only , that point lies on and is the intersection. If it contains only , the point is outside the bounds of , so the intersection is empty. Two point inputs have a common point only when their locations are the same.
The diamond in each group's second panel identifies an input consisting of just one point. It does not mean the input has area. The third panel still uses a dot for a point intersection.
A Shared Segment: An Overlap Interval
Now let segment run from to . Both it and lie on the horizontal axis.
A common point must satisfy both
The second condition requires to be at least , and the first requires it to be at most . Thus a common point must satisfy .
Conversely, take any number satisfying . It is between and and also between and . Therefore, belongs to both segments.
Together, these two directions show that the intersection is exactly the complete closed interval from to , including both endpoints. Its length is ; it is not just a single point.
Reporting only two endpoint intersections would be wrong, because intermediate points such as also belong to the intersection. We use the interval's two endpoints to describe the entire common part, not to claim that only those two points are shared.
If we add a segment from to , it intersects and separately at . These are results for two other input pairs. The points contained in and have not changed, so their intersection remains one complete interval from to . It must not be split into two results at .
These six panels form three before-and-after pairs. Read each pair as “before adding C” and then “after adding C.” If there is not enough space, the second panel wraps onto the next row but remains in the same group. The first two pairs show A and B separately alongside the newly added C, so that coincident segments do not hide one another. The last pair shows only the intersection of A and B, which remains the same complete interval. This compares the intersections before and after adding an input; it is not a sweep-line execution sequence.
Why Can the Common Part Not Be Two Separate Pieces?
We have seen empty intersections, points, and intervals of nonzero length. For closed segments, these cover every possibility.
First consider an input of length . It contains only one point, so the common part can only be that point or the empty set; it cannot contain more points.
Now consider two segments of nonzero length. If the common part has no points, it is empty; if it has exactly one, it is a point intersection. What remains to show is this: as soon as there are two distinct common points, the common part must be one complete segment.
Call the two distinct common points and . Two distinct points determine one line. The lines containing both segments pass through and , so they are the same line.
If this line is not vertical, order its points by increasing horizontal coordinate. On this line, each horizontal coordinate corresponds to exactly one point. A segment extends continuously from one endpoint to the other, containing the points at every horizontal coordinate in between. If the line is vertical, use vertical coordinates instead; the reasoning is the same.
Compare the segments in this order. Let be the later of their two earlier endpoints, and let be the earlier of their two later endpoints.
No common point can precede : it would be before the beginning of one segment. Nor can it follow : it would be beyond the end of one segment. Thus every common point must lie between and .
Conversely, every point from to is no earlier than either segment's earlier endpoint and no later than either segment's later endpoint. It therefore belongs to both segments. Since we already have two distinct common points, must precede and cannot coincide with it.
The common part is therefore exactly the complete closed interval of nonzero length from to ; there can be no gap inside it. This establishes all three possibilities. Here we use this fact to specify the shape of a result. Chapter 3 will explain how to compute the result from arbitrary endpoints.
Record Both the Location and the Input Pair
Consider this small example with three inputs:
| Input number | Endpoints |
|---|---|
| and | |
| and | |
| and |
Input lies on the horizontal axis, and input on the vertical axis. Their only common point is the origin : a common point must satisfy both and , and the origin is within both segments' endpoint bounds. Input contains only the origin, which also belongs to each of the first two segments. The results are therefore:
| Input pair | Complete intersection |
|---|---|
| and | Point |
| and | Point |
| and | Point |
Reading left to right and then top to bottom, the first three panels show inputs , , and separately, and the fourth places them together. All three contain the origin, but the results must still list the three input pairs separately, as in the table. The diamond still denotes the point input at the origin; we must not omit this input merely because it coincides with the intersection of the two segments.
There is only one geometric location but three intersecting input pairs, so we keep three results. Writing only “the origin” would not tell us which inputs intersect one another.
Return to the three coincident inputs at the start. They also form three pairs: and , and , and and . Each input contains exactly the same points, so every pair's intersection is the complete interval from to . Coinciding geometrically does not remove any input's identity.
We can therefore state our goal precisely: find every unordered pair of original inputs with a nonempty intersection, and keep one result for each pair, recording the input pair and its complete intersection.
How Do We Check Every Pair Once?
Practice enumerating pairs with four inputs. Here we list only the pairs to check; their locations do not affect this enumeration.
| Current input | Pair only with higher-numbered inputs | Checks in this row |
|---|---|---|
| and , and , and | ||
| and , and | ||
| and | ||
| No higher-numbered input |
This checks pairs in total. For each pair, compute the intersection of its two inputs. Skip empty intersections, and record nonempty ones using the rules above.
The same method works for more inputs. Let us explain why it misses no pair and checks none twice.
Why is no pair missed? Take any two distinct inputs. One must have the smaller number and the other the larger. In the row for the smaller number, the rule pairs it with every larger number, so this pair must be checked. This applies to any two distinct inputs, regardless of their positions or whether they intersect.
Why is no pair repeated? A pair can occur only in the row for its smaller number. In the row for the larger number, the rule allows only still larger numbers; it never returns to the smaller one. In the smaller number's row, each larger number occurs only once. Thus the pair is checked exactly once in total.
The rule also avoids pairing an input with itself, because “higher-numbered” excludes an equal number. Provided each two-segment check computes the complete intersection correctly, the enumeration finds every intersecting input pair and keeps at most one result per pair. This is the baseline against which we can compare later algorithms.
How Many Pairs Must Be Checked?
Let denote the number of original inputs. For example, with four inputs, . We are counting inputs, so coincident inputs still count separately.
First suppose . To count the distinct pairs, temporarily allow both possible orders. There are choices for the first input and then choices for a different second input. Each first choice has second choices, giving a total of
But this counts each pair twice: for example, choosing then , and choosing then . Every pair of distinct inputs has exactly these two orders and no third; we need only one. Dividing the count by gives
We have already proved that the pairwise method checks each unordered input pair exactly once, so this is also its number of checks.
Substitute , doing the subtraction in parentheses before multiplication and division:
which agrees with the pairs counted row by row in the table.
With no inputs or only one, we cannot choose two distinct inputs, so there are checks. The formula also gives and . We establish these boundary cases first from “there is no pair to choose”; there is no need to interpret a negative number as a number of choices.
The number of checks grows quickly as the input count increases:
| Input count | Number of checks |
|---|---|
Even if no two segments intersect, the pairwise method still checks this many pairs and produces no intersection results. Thus the number of pairs checked and the number of pairs that actually intersect are different quantities.
On the other hand, inputs for which every pair intersects do exist. For example, let all inputs occupy the same nonzero-length segment. Every pair's intersection is that entire segment, so the number of result records is also . If the results must be listed one by one, no method can avoid the work of outputting them.
Also, the number of checks is not the complete running time. Each check involves geometric decisions and calculations, and storing a result takes work too. With exact fractions, arithmetic can also become more expensive as the numbers get longer. This chapter counts only “how many pairs must be checked”; it does not claim that a check takes a fixed amount of real time. Later chapters will develop the full workload analysis.
From the Baseline to a Sweep Line
We now have a precise goal: organize results by original input pair, retaining a point or one complete overlap interval for each intersecting pair. We also have a reliable baseline: checking pairs one by one misses none and repeats none, but checks pairs regardless of how many actually intersect.
The next question is: when many segments do not intersect, can we use their relative positions to check fewer pairs while still finding every result?
Chapter 2, in Part 1: The Sweep and Three Types of Events and Part 2: Why No Intersection Is Missed, explores this question under explicit simplifying assumptions.