Skip to main content

Liang-Barsky: (6,100)-(60,5)

Short answer

Line from (6,100) to (60,5); window (10,10)–(90,90). Δx=54, Δy=−95. p,q yield entering u from left (0.074) and top (0.1053), leaving from right (1.556) and bottom (0.9474). u1=max(0,0.074,0.1053)=0.1053, u2=min(1,0.9474)=0.9474. Clipped endpoints: x1'=6+0.1053×54≈11.68, y1'=100−0.1053×95=90; x2'=6+0.9474×54≈57.16, y2'=100−0.9474×95=10. Clipped line: (11.68, 90) to (57.16, 10).

Use Liang-Barsky line clipping algorithm to clip a line starting from (6,100) and ending at (60, 5) against the window having its lower left corner at (10, 10) and upper right corner at (90, 90).

Given: P1(6,100), P2(60,5); window xmin = 10, ymin = 10, xmax = 90, ymax = 90.

Parametric line: x = x1 + u·Δx, y = y1 + u·Δy, 0 ≤ u ≤ 1. Here Δx = 60 − 6 = 54, Δy = 5 − 100 = −95.

p1 = −Δx = −54   q1 = x1 − xmin = −4     (left)
p2 =  Δx =  54   q2 = xmax − x1 = 84     (right)
p3 = −Δy =  95   q3 = y1 − ymin = 90     (bottom)
p4 =  Δy = −95   q4 = ymax − y1 = −10    (top)

For p < 0 the line enters the window, and u = q/p is a candidate for u1 = max(0, ...); for p > 0 it leaves, and u = q/p is a candidate for u2 = min(1, ...).

Edgepqu = q/p and remark
left−54−4entering, u = 0.074
right5484leaving, u = 1.556
bottom9590leaving, u = 0.9474
top−95−10entering, u = 0.1053

u1 = max(0, entering values) = 0.1053, u2 = min(1, leaving values) = 0.9474.

Since u1 < u2, part of the line is visible.

x1' = x1 + u1·Δx = 6 + 0.1053×54 = 11.68
y1' = y1 + u1·Δy = 100 + 0.1053×(−95) = 90
x2' = x1 + u2·Δx = 6 + 0.9474×54 = 57.16
y2' = y1 + u2·Δy = 100 + 0.9474×(−95) = 10

Answer: the clipped line is from (11.68, 90) to (57.16, 10).

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Graphics chapter 3 questions →