Skip to main content

Liang-Barsky: (-2,2)-(45,40)

Short answer

Compute p and q values: left entering u=0.0851, bottom entering u=0.0789, right leaving u=0.7872, top leaving u=1.263. u1 = max(0, 0.0851, 0.0789) = 0.0851, u2 = min(1, 0.7872, 1.263) = 0.7872. Then x1' = −2 + 0.0851×47 = 2, y1' = 2 + 0.0851×38 ≈ 5.23, x2' = −2 + 0.7872×47 = 35, y2' = 2 + 0.7872×38 ≈ 31.91. Clipped line: (2, 5.23) to (35, 31.91).

Perform clipping operation for the following using Liang Barsky line clipping algorithm: Clipping window: (Xmin, Ymin) = (2,5) and (Xmax, Ymax) = (35,50); Line: (x1, y1) = (-2,2) and (x2, y2) = (45,40).

Given: P1(−2,2), P2(45,40); window xmin = 2, ymin = 5, xmax = 35, ymax = 50.

Parametric line: x = x1 + u·Δx, y = y1 + u·Δy, 0 ≤ u ≤ 1. Here Δx = 45 − (−2) = 47, Δy = 40 − 2 = 38.

p1 = −Δx = −47   q1 = x1 − xmin = −4     (left)
p2 =  Δx =  47   q2 = xmax − x1 = 37     (right)
p3 = −Δy = −38   q3 = y1 − ymin = −3     (bottom)
p4 =  Δy =  38   q4 = ymax − y1 = 48     (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−47−4entering, u = 0.0851
right4737leaving, u = 0.7872
bottom−38−3entering, u = 0.0789
top3848leaving, u = 1.263

u1 = max(0, entering values) = 0.0851, u2 = min(1, leaving values) = 0.7872.

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

x1' = x1 + u1·Δx = −2 + 0.0851×47 = 2
y1' = y1 + u1·Δy = 2 + 0.0851×38 = 5.23
x2' = x1 + u2·Δx = −2 + 0.7872×47 = 35
y2' = y1 + u2·Δy = 2 + 0.7872×38 = 31.91

Answer: the clipped line is from (2, 5.23) to (35, 31.91).

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Graphics chapter 3 questions →