Learn
Lesson · Geometric Algorithms · Segments, and the zero sign

Four Zero Signs and Two Different Answers

Collinear segments produce four zero determinants whatever they do. Two of the lab's worked examples have exactly the same four signs — 0, 0, 0, 0 — and opposite answers: one pair overlaps and one pair has a gap. Since the inputs agree on every quantity the sign test computes, no amount of care with the signs can distinguish them, and the collinear case has to be finished as a one-dimensional interval question.

overlap: (0, 0)–(6, 0) and (4, 0)–(10, 0) signs 0, 0, 0, 0 they meet apart: (0, 0)–(4, 0) and (6, 0)–(10, 0) signs 0, 0, 0, 0 they miss identical four signs, opposite answers: the signs are not a sufficient statistic the bounding boxes do separate these two: overlapping, and not a degenerate segment is a point, and all four signs are zero again the collinear case is an interval overlap along one direction
One pair of inputs that settles what the four signs can decide

Core ideas

What this lesson establishes

A pair of inputs, the argument they make, and the machinery that actually finishes the case.

1

A determinant is zero everywhere on a line

That is not a defect of the orientation test, it is what the test means: orient(a, b, c) = 0 says c is on the line through a and b, with no information about where. Once all four points are collinear, all four determinants are zero and every one of them will stay zero however you perturb the points along the line. There is simply no more signal to extract.

2

Two inputs, one signature, opposite answers

(0, 0)–(6, 0) against (4, 0)–(10, 0) overlaps on the interval from 4 to 6. (0, 0)–(4, 0) against (6, 0)–(10, 0) has a gap from 4 to 6. Both produce 0, 0, 0, 0. Any function of the four signs must give them the same answer, and the right answers are different, so no such function is the intersection test. That is a proof and not a warning, and it takes two lines of the lab to demonstrate.

3

What finishes it is a one-dimensional question

Project both segments onto the direction of the first: t₀ = (q₁ − p₁)·r and t₁ = t₀ + (q₂ − q₁)·r, where r = p₂ − p₁. The first segment occupies [0, r·r] in that coordinate, the second occupies the interval between t₀ and t₁, and the two meet exactly when those intervals overlap. Every quantity there is an integer dot product, so the whole test is exact, and it uses no determinant.

The material

Why no sign test can work, and what does

The impossibility argument, the interval test that finishes the case, and the degenerate inputs that reach it.

Definition · Collinear segments, and the projection coordinate

Two segments are collinear when all four endpoints lie on one line, which makes all four orientation determinants zero. For collinear segments with r = p₂ − p₁ nonzero, define the projection coordinate of a point x as (x − p₁)·r. In this coordinate p₁ is at 0 and p₂ is at r·r, and both are integers whenever the endpoints are.

Theorem · No function of the four signs is the intersection test

There exist two pairs of segments whose four orientation signs are equal, one of which meets and one of which does not. Consequently any intersection test computed from the four signs alone is wrong on at least one of them.

Take p₁p₂ = (0, 0)–(6, 0) with q₁q₂ = (4, 0)–(10, 0), and p₁p₂ = (0, 0)–(4, 0) with q₁q₂ = (6, 0)–(10, 0). In both, all four points lie on the line y = 0, so all four determinants are zero and the sign vectors are both (0, 0, 0, 0).

The first pair shares every point with 4 ≤ x ≤ 6, so it meets. The second pair has the first segment ending at x = 4 and the second starting at x = 6, so no point is on both and it does not meet. A function of the sign vector returns one value on that vector, and it cannot be both true and false.

□

That argument is short and it is worth stating as a theorem rather than as a remark, because the usual reaction to the collinear case is to look for a cleverer combination of the signs. There is none, and the reason is structural: the signs are a function of which side of each line each point is on, and when everything is on the line, every input with that property has the same signature.

Example · The two inputs, side by side

Select the overlapping collinear worked example and read the KPI row: proper crossing no, touching yes, bounding boxes overlap yes, verdict they meet. Select the one with the gap: proper crossing no, touching no, bounding boxes overlap NO, verdict they miss. The four-sign table above is byte-for-byte identical between the two runs, and every other row on the page changes.

One label to distrust while you are there. The worked example with the gap is offered as “collinear, boxes touching, no overlap”, and the boxes are not touching: they are the intervals from 0 to 4 and from 6 to 10, with two units between them, and the widget's own bounding-box row reports NO on that input. Read the row, not the label. While you are checking: none of the seven worked examples has overlapping boxes AND segments that miss, so the one case that shows the filter failing to decide has to be typed. 0, 0; 4, 4; 2, 0; 4, 1 does it — boxes overlapping, no crossing, and the status line then says the boxes are a filter and never an answer.

The bounding boxes DO separate these two, and it is worth working out why, because the answer is more interesting than a coincidence. Along a line, both coordinates are monotone in the parameter: if the direction has rx ≠ 0 then x increases or decreases steadily, and if rx = 0 the segment is vertical and y does. So for COLLINEAR segments, overlapping boxes and overlapping intervals along the line are the same condition, and the box test is not a filter at all here — it is exact. Running 197,506 random collinear pairs past both tests produces not one disagreement.

That does not make the box test the answer, for two reasons. It stops being exact the moment the segments are not collinear, which is the whole of the rest of the problem and where 0, 0; 4, 4; 2, 0; 4, 1 lives. And it says nothing about the degenerate case below, where one segment is a point. The projection coordinate is the form worth learning because it is the same computation in both, and because it states the question in the coordinate the answer actually lives in rather than in two coordinates that happen to agree with it.

Degenerate segments reach the same branch

A segment whose two endpoints coincide is a point. The lab has one: the point (3, 2) against the segment from (0, 0) to (6, 4), which passes through it. All four determinants are zero again, proper is false, and the right answer is yes. The parametric route handles this by noticing that r·r = 0 and falling back to asking whether the point lies on the other segment; a route that divided by r·r would have failed here instead.

That is the third distinct family that produces four zeros: collinear and overlapping, collinear and disjoint, and degenerate. A fourth is nearly there — a shared endpoint gives two zeros rather than four. The lab's preset list walks all of them deliberately, and four of its seven entries are inputs the proper test alone gets wrong.

How the interval test is kept exact

The projection coordinates t₀ and t₁ are dot products of integer vectors, so they are integers, and the first segment occupies [0, r·r] which is also an integer interval. The test is then max(t₀, t₁) ≥ 0 and min(t₀, t₁) ≤ r·r, two integer comparisons. No normalisation, no direction vector of unit length, no division.

It is worth appreciating how little this costs. The entire collinear branch is a handful of multiplications and two comparisons, and it converts a test that is right on general position into one that is right on everything. The usual reason it is missing from an implementation is not cost; it is that the author never constructed an input that reaches it.

Interactive

Do two segments meet, including every case where one sign is zero

Four orientations against an exact solve for the two parameters

Do these two segments meetfour orientation signs against an exact parametric solve
the first segmentthe secondthey meetthey do not

Method

Finishing a collinear pair

Once the determinant is zero, stop thinking about sides and start thinking about intervals.

1

Confirm the case rather than assuming it

Four zeros means all four points are on one line. Two zeros usually means a shared or touching endpoint. One zero means one endpoint is on the other's line. Each leads somewhere different, so read all four before branching.

2

Choose a direction and project

Take r = p₂ − p₁ and compute (x − p₁)·r for the other segment's endpoints. If r·r is zero the first segment is a point, and the question is just whether that point lies on the other segment.

3

Compare the two intervals with integers

The first segment is [0, r·r]; the second is the interval between the two projected values, in whichever order they came out. They meet when the intervals overlap, which is two comparisons. Everything here is an integer and nothing is normalised.

4

Test both members of the identical-signature pair

Any implementation of this branch should be run on the overlapping pair and the pair with a gap. They are the minimal pair of inputs that distinguishes a correct collinear branch from a missing one, and a test suite without something like them will pass on an implementation that has no collinear branch at all.

What the signs can and cannot decide

Score 0 / 0

The two inputs, and every quantity the page computes for each

Both are horizontal and both give four zero determinants. Only one of them meets.

OVERLAP APART p1, p2 (0,0) (6,0) (0,0) (4,0) q1, q2 (4,0) (10,0) (6,0) (10,0) orient(q1, q2, p1) 0 0 orient(q1, q2, p2) 0 0 orient(p1, p2, q1) 0 0 orient(p1, p2, q2) 0 0 signs 0, 0, 0, 0 0, 0, 0, 0 proper crossing no no touching yes no bounding boxes overlap yes no verdict from the signs they meet they miss verdict from the parameters they meet they miss projection coordinate, r = (6,0) so r·r = 36 r = (4,0) so r·r = 16 q1 at (q1 − p1)·r 24 24 q2 at (q2 − p1)·r 60 40 first segment occupies [0, 36] [0, 16] second occupies [24, 60] [24, 40] intervals overlap? yes no

The top half of that table is the same twice, and the bottom half is where the answer lives. That is the argument in its most compact form: everything the sign test computes is identical, so the sign test cannot be the answer.

The projection rows are worth reading carefully, because they show the general machinery producing the right answer on both. In the overlapping case the second segment's interval starts at 24 and the first ends at 36, so they share [24, 36]. In the other case the first ends at 16 and the second starts at 24, so they do not. Note that 24 appears in both columns and means different things, because r is different — the coordinate is relative to the first segment's own direction and length.

For a faded rehearsal, construct a diagonal version: (0, 0)–(6, 6) against (4, 4)–(10, 10), and then against (8, 8)–(10, 10). The supplied first move is that r = (6, 6) so r·r = 72 in both. Compute the two projection intervals for each and predict the verdicts; then check that the bounding boxes agree with them, as the monotonicity argument above says they must, and say what would have to change about the input for them to stop agreeing.

Common mistakes

1
Looking for a cleverer combination of the four signsThere is not one, and the two-input argument on this page proves it in three lines. The instinct is natural because the proper test is so nearly complete, but the missing information is not hiding in the signs; it was never in them.
2
Concluding from the collinear case that the box test is enoughIt really is exact on collinear segments — that is proved above and checked on nearly two hundred thousand random collinear pairs — and that is a genuinely narrow result. On segments that are not collinear the boxes overlap whenever the two rectangles do, which has nothing to do with whether the segments meet: 0, 0; 4, 4; 2, 0; 4, 1 has overlapping boxes and no crossing. The correct reading is that the box test decides the collinear branch and filters the rest.
3
Testing an intersection routine only on crossingsA test suite of properly crossing and clearly separate pairs passes on an implementation with no collinear branch whatsoever. The minimum useful suite is the seven worked examples on this page, or something like them: a proper crossing, a T-junction, a shared endpoint, a parallel pair, a degenerate segment, and the two collinear cases with the same signs and opposite answers.

Check your understanding

✓
Finish when you can prove that the four signs are insufficient and implement the branch that finishes the case.

You should be able to construct the identical-signature pair from memory, state why no function of the signs can separate them, project a collinear pair onto the first segment's direction and decide the overlap in integers, and say which degenerate families produce four zeros and which produce two.

Note: One pair of segments is a question about two objects. “The Sweep Line and the Work It Does Not Save” asks it about many at once, and measures how many of the possible pairs a sweep actually tests — including an input where the answer is all of them.

Kept in this browser only, for you. Nothing is sent anywhere and nothing checks it. Carry it to another device.

Feedback and recommendations

Something to change about this lesson? Write it down, tick it off when it is handled, and export the list when you want to act on it. Kept in this browser only: nothing is sent anywhere, and nobody is notified.

No recommendations yet for this lesson.