Skip to main content

Handling vertical segments with a shear

A vertical segment passes through intersections at two different heights. Both have the same xx coordinate. At which height should this segment sit in the active order?

This is Chapter 7 of the segment-intersection series. It incorporates vertical inputs into Chapter 6's point-by-point sweep: transform all inputs together, apply the existing rules in the new coordinates, then restore the intersection results. The shear topics provide mathematical proofs. Here we state their results and conditions where needed and follow one set of inputs through the process. You need not read the complete topic first.

Section 1: Where a vertical segment gets stuck​

Take three closed segments, whose names denote fixed original identities:

InputEndpointsRange in the original coordinates
V\teachBlue{V}(0,0),(0,3)(0,0),(0,3)x=0x=0, 0≤y≤30\le y\le3
A\teachOrange{A}(−1,1),(1,1)(-1,1),(1,1)y=1y=1, −1≤x≤1-1\le x\le1
B\teachViolet{B}(−1,2),(1,2)(-1,2),(1,2)y=2y=2, −1≤x≤1-1\le x\le1

Call the position where AA crosses VV P=(0,1)P=(0,1), and where BB crosses VV Q=(0,2)Q=(0,2). Both points lie within their respective closed ranges. A,BA,B lie on distinct horizontal lines and have no common point. Of the three input pairs, only V,AV,A and V,BV,B intersect.

Figure 1: Original inputs V, A, B. V extends along x=0 from O to height 3; P and Q are at heights 1 and 2.Figure 1: Original inputs V, A, B. V extends along x=0 from O to height 3; P and Q are at heights 1 and 2.
Figure 2: Transformed inputs drawn with the demonstration coefficient one half. P′ and Q′ are ordered left to right. This figure does not use the actual calculation coefficient.Figure 2: Transformed inputs drawn with the demonstration coefficient one half. P′ and Q′ are ordered left to right. This figure does not use the actual calculation coefficient.

Read Figures 1 and 2 as a numbered pair, retaining that order when they wrap onto separate rows. Each has an original size of 320 × 260 and equal horizontal and vertical units; OO is the origin. All transformed figures here use the demonstration coefficient svis=1/2s_{\mathrm{vis}}=1/2 to magnify the shear. It is not the ss used below, and horizontal distances in the figures cannot check the sweep calculations. Both original and demonstration figures are teaching diagrams, not real execution traces. Coordinate tables, formulas, and event tables always use the actual coefficient.

Chapter 6's reason for updating only the current block uses this condition: a nonvertical line has only one height at a fixed xx coordinate. One nonzero input therefore cannot participate in both a low and a high event in one column.

Here VV covers every height from 00 to 33 at x=0x=0, containing both PP and QQ. Treating it as one position with a single height fails: choosing 11 loses its participation at QQ, while choosing 22 cannot describe its participation at PP. Assigning an arbitrary slope does not change this fact. We must first make the inputs satisfy the old rules' conditions, then use those rules.

Section 2: Transform the inputs into a form the sweep can handle​

Reuse the transformation from How a shear changes coordinates:

x′=x+sy,y′=y.x'=x+sy,\qquad y'=y.

x,yx,y are original coordinates and x′,y′x',y' are new coordinates. The prime distinguishes coordinates, not input identities. The same positive number ss, called the shear coefficient, is chosen for this computation. To transform a point, multiply its yy coordinate by ss and add that to its original xx coordinate; leave its height unchanged. We fix the axes and plot the calculated coordinates as new points, without repeating the interpretation of tilted coordinate axes.

Every endpoint of every input uses the same ss. A shared original position therefore undergoes the same transformation: whichever input we compute along, we get the same new position. Different coefficients for different lines would not transform the whole figure uniformly, so the intersection-correspondence result would not apply.

How the coefficient ensures the old conditions​

For rational coordinates, follow Integer scaling and intersection denominators: choose a positive integer common denominator DD making every endpoint's Dx,DyDx,Dy integers. Let MM be the maximum of 11 and the absolute values of these integers. Use the choice established in Event spacing and the shear coefficient:

s=1256(M+1)5.s=\frac{1}{256(M+1)^5}.

This preserves the left-to-right order of endpoints and actual intersections with originally different xx coordinates. The topics above derive the denominator bound, fifth power, and constant. Scaling is used only to select the coefficient; the original coordinates still use the same ss, without an extra multiplication or division by DD.

The result in Equal horizontal coordinates, degenerate inputs, and original coordinates directly checks both input types. Originally different endpoint xx coordinates remain different x′x' coordinates by order preservation. For endpoints with the same xx but different heights, the positive coefficient places the lower endpoint left of the higher. Thus every nonzero input becomes nonvertical, and originally nonvertical inputs do not become vertical. This supplies the missing condition. Zero-length inputs remain points; the statement does not turn them into nonzero segments.

The main example already has integer endpoints: take D=1D=1. Its largest absolute coordinate is 33, so M=3M=3. It meets the same conditions as the topic's example with largest absolute coordinate 3, so reuse the result calculated there:

s=1262144.s=\frac{1}{262144}.

We retain the letter ss below. It always equals this exact fraction, never the demonstration coefficient or a decimal approximation.

Input identityTransformed left endpointTransformed right endpoint
VV(0,0)(0,0)(3s,3)(3s,3)
AA(−1+s,1)(-1+s,1)(1+s,1)(1+s,1)
BB(−1+2s,2)(-1+2s,2)(1+2s,2)(1+2s,2)

For example, the upper endpoint of VV has x′=0+s×3=3sx'=0+s\times3=3s, and the left endpoint of AA has x′=−1+s×1=−1+sx'=-1+s\times1=-1+s. Each row retains its original endpoint heights. The new horizontal length of VV is 3s>03s>0, while those of A,BA,B are both 22.

Section 3: How original events correspond to transformed events​

First confirm that the transformed problem is still the original problem. Why shearing preserves intersections proves that one fixed coefficient maps an entire closed segment to the entire closed segment between its transformed endpoints. The transformation can be uniquely undone, so no common points are lost or introduced. This holds for any rational coefficient and does not depend on order preservation by a small coefficient.

The main example's two common points therefore become

P′=(0+s×1,1)=(s,1).P'=(0+s\times1,1)=(s,1). Q′=(0+s×2,2)=(2s,2).Q'=(0+s\times2,2)=(2s,2).

Their new x′x' coordinates differ by 2s−s=s>02s-s=s>0. The bottom-to-top pair P,QP,Q in one original column becomes the left-to-right pair P′,Q′P',Q'. This is more than renaming points: VV reaches height 11 at x′=sx'=s, then height 22 at x′=2sx'=2s. One order position no longer has to represent two heights in one column.

For other inputs, both same-column separation and preservation of order between originally different columns follow from the coefficient result above. Chapter 6's complete event order can therefore be used in new coordinates. Originally coincident positions remain coincident: same-point participants must not be split into separate processing times. The preserved order is that of geometric event positions; endpoint information and input identifiers must still be retained separately.

Collinearity is also preserved by the line result in the intersection topic. Originally collinear nonzero inputs remain on one line. Distinct lines cannot merge into one because the transformation is uniquely reversible. Chapter 5's collinear groups are therefore organized by lines in the new coordinates, retaining each original identity inside. Point inputs have no unique supporting line and do not join these groups.

Keep a third responsibility separate: exact rational arithmetic prevents fractions from being truncated to finite decimals. The invertible, whole-segment-preserving transformation gives intersection correspondence; the chosen coefficient gives event order preservation; fraction arithmetic avoids rounding error. A small coefficient is not itself a reason for exact calculation.

Section 4: Complete the sweep in the new coordinates​

Now sweep the transformed inputs. Heights, slopes, endpoint ranges, candidate intersections, and future comparisons all use x′,y′x',y'. The names V,A,BV,A,B still refer to the same original inputs and are not renumbered when their order changes.

Write the new lines and coverage ranges​

For VV, originally x=0x=0, substitution gives x′=syx'=sy. Since y′=yy'=y, this is x′=sy′x'=sy'. As s>0s>0, divide both sides by ss to get y′=x′/sy'=x'/s. The other two heights remain unchanged:

InputHeight in new coordinatesNew slopeClosed range of new x′x' coordinates
VVy′=x′/sy'=x'/s1/s=2621441/s=262144[0,3s][0,3s]
AAy′=1y'=100[−1+s,1+s][-1+s,1+s]
BBy′=2y'=200[−1+2s,1+2s][-1+2s,1+2s]

Ranges come from transformed endpoints. A slope states how much new height changes when the new x′x' coordinate increases by 11. We cannot use an old slope for originally vertical VV, or its old range x=0x=0 alone to judge a new intersection.

From the start events to the two intersections​

Because 0<s=1/262144<1/20<s=1/262144<1/2, we have 2s<12s<1. The horizontal inputs' left endpoints satisfy −1+s<−1+2s<0-1+s<-1+2s<0, so both start before VV. AA is alone when it joins, and BB joins above it. These horizontal lines are parallel; no intersection is scheduled.

At (0,0)(0,0), VV joins at height 00, below A,BA,B. The line intersection of new neighbors V,AV,A satisfies x′/s=1x'/s=1. Multiplying both sides by ss gives x′=sx'=s, at height 11. Since 0<s<3s0<s<3s and −1+s<s<1+s-1+s<s<1+s, the candidate is in both closed ranges and strictly right of the current position, so register P′P'. AA still separates V,BV,B; this start event has not made them direct neighbors.

At P′P', both V,AV,A have height 11 and BB has height 22. First report P′P' for V,AV,A, then use Chapter 3's slope relation on the right: AA has slope 00, less than VV's 1/s1/s, so the right-side bottom-to-top order becomes A,V,BA,V,B.

Only now do V,BV,B become new neighbors and get checked. Multiplying x′/s=2x'/s=2 by ss gives x′=2sx'=2s, height 22. It satisfies 0<2s<3s0<2s<3s and −1+2s<2s<1+2s-1+2s<2s<1+2s, so both inputs cover it. Also 2s>s2s>s, placing it strictly after P′P', so register Q′Q'. This uses Chapter 6's distinct future and coverage checks: actual range membership and still awaiting processing must be checked separately.

At Q′Q', only V,BV,B, both at height 22, participate; AA at height 11 does not. After reporting Q′Q' for V,BV,B, order them B,VB,V on the right since 0<1/s0<1/s. The full bottom-to-top order is A,B,VA,B,V. New neighbors A,BA,B are parallel and have no new intersection.

Here are all the events. The order column describes the state after processing the event, not an arbitrary ordering of equal-height participants at the meeting point.

New event positionCurrent actionBottom-to-top order after processing
(−1+s,1)(-1+s,1)AA startsAA
(−1+2s,2)(-1+2s,2)BB starts; A,BA,B are parallelA,BA,B
(0,0)(0,0)VV starts; discover and register P′P'V,A,BV,A,B
P′=(s,1)P'=(s,1)Report V,AV,A; after updating, discover and register Q′Q'A,V,BA,V,B
Q′=(2s,2)Q'=(2s,2)Report V,BV,B; A,BA,B are parallelA,B,VA,B,V
(3s,3)(3s,3)VV endsA,BA,B
(1+s,1)(1+s,1)AA endsBB
(1+2s,2)(1+2s,2)BB endsEmpty

The last three endpoints really occur in this order: subtracting ss from both sides makes 3s<1+s3s<1+s equivalent to 2s<12s<1; and 1+s<1+2s1+s<1+2s follows from s>0s>0. No other input passes through these end events, so no results are added. All endpoints and both real intersections have been processed.

This example incorporates transformed inputs into the sweep without reproving neighbor discovery. General inputs still use Chapter 4's same-point participant collection, Chapter 5's coverage-extension checks, and Chapter 6's complete future comparison. Their nonvertical condition is now satisfied. A collinear group's farthest right endpoint must also use transformed endpoints' x′x' coordinates, not a mixture with old endpoints' xx coordinates.

Section 5: Return the answer to the original figure​

The sweep obtained intersections in the new coordinates. Use the inverse formulas from the shear topic:

x=x′−sy′,y=y′.x=x'-sy',\qquad y=y'.

For the result P′=(s,1)P'=(s,1) of V,AV,A, substitution gives

x=s−s×1=s−s=0,y=1.x=s-s\times1=s-s=0,\qquad y=1.

This restores P=(0,1)P=(0,1). For the result Q′=(2s,2)Q'=(2s,2) of V,BV,B, likewise obtain

x=2s−s×2=2s−2s=0,y=2.x=2s-s\times2=2s-2s=0,\qquad y=2.

This restores Q=(0,2)Q=(0,2). The final answer has two results attached to original unordered input pairs: PP for V,AV,A and QQ for V,BV,B; A,BA,B has empty intersection. Do not return two points without input-pair identities, or mistake the new-coordinate P′,Q′P',Q' for answers in the original figure.

Restore an entire overlap interval as an entire interval​

Take a separate short example with only VV and a new input W\teachEmerald{W}, whose endpoints are (0,1),(0,2)(0,1),(0,2). Neither AA nor BB is present. The largest absolute endpoint coordinate remains 33, so the actual coefficient is still s=1/262144s=1/262144.

Figure 3: Only V and W are present. W lies inside original vertical segment V from height 1 to 2. The dashed segment is V; the thicker solid segment is W and also this pair’s complete intersection.Figure 3: Only V and W are present. W lies inside original vertical segment V from height 1 to 2. The dashed segment is V; the thicker solid segment is W and also this pair’s complete intersection.
Figure 4: After the demonstration shear they remain on the same line, with the whole of W inside V; the dashed and solid segments have not separated. The demonstration coefficient is one half.Figure 4: After the demonstration shear they remain on the same line, with the whole of W inside V; the dashed and solid segments have not separated. The demonstration coefficient is one half.

After transformation, VV covers [0,3s][0,3s] and WW covers [s,2s][s,2s], both on y′=x′/sy'=x'/s. By Chapter 5's rule of reporting the complete intersection when a new member joins, when WW joins at (s,1)(s,1) it reports, with same-group member VV, the complete interval from (s,1)(s,1) to (2s,2)(2s,2). These positions are not two point results: the solid line emphasizes the entire common part.

Restore the lower endpoint: x=s−s×1=0,y=1x=s-s\times1=0,y=1; restore the upper: x=2s−s×2=0,y=2x=2s-s\times2=0,y=2. By the whole-segment correspondence cited in Section 3, restore the entire segment determined by these boundaries, obtaining the complete overlap interval from (0,1)(0,1) to (0,2)(0,2). Keep the input pair V,WV,W, without merging identities. Even if another crossing occurs inside, use Chapter 5's classified reporting, without splitting this interval or reporting it again as a point.

Point inputs still participate only in their own event​

Take another separate short example with only VV and two point inputs Z1,Z2Z_1,Z_2, each with both endpoints at P=(0,1)P=(0,1). There are no A,B,WA,B,W. Use the same actual ss.

Figure 5: In the original coordinates, V meets two point inputs Z1, Z2 at the same position. Both the ring and diamond are centered at P; the marks do not represent areas.Figure 5: In the original coordinates, V meets two point inputs Z1, Z2 at the same position. Both the ring and diamond are centered at P; the marks do not represent areas.
Figure 6: After the demonstration shear, both point inputs still occupy the same P′. Neither becomes a positive-length segment, and their positions do not separate. The demonstration coefficient is one half.Figure 6: After the demonstration shear, both point inputs still occupy the same P′. Neither becomes a positive-length segment, and their positions do not separate. The demonstration coefficient is one half.

Both endpoints become (s,1)(s,1) under the same transformation, so each input still has zero length. By Chapter 4's rule that point inputs participate in only this event, merge both point identities with nonzero participant VV at P′P'. This produces three point-result pairs: V,Z1V,Z_1, V,Z2V,Z_2, and Z1,Z2Z_1,Z_2. They share a position but have different identities. Each result is restored to PP using x=s−s×1=0,y=1x=s-s\times1=0,y=1.

Z1,Z2Z_1,Z_2 acquire neither slopes nor later positions in the active order. VV continues through this point and remains the only active input afterward. This connects the existing point-participation rule across the transformation; no new sweep mechanism is needed.

The inputs now satisfy the sweep conditions through one uniform coefficient; all decisions use new coordinates; inverse transformation restores points or complete intervals; and original input pairs are retained throughout. Continue with Chapter 8: Putting all the rules into one sweep to follow a complete mixed-input example. General correctness and total work remain for Chapters 9 and 10 respectively.