Skip to main content

Liang-Barsky: (5,120)-(80,7)

Short answer

Using Liang-Barsky with window (10,10)-(100,100) on line (5,120)-(80,7), u1=0.177, u2=0.9735, giving clipped points (18.27,100) and (78.01,10).

Find the clipped region in window of diagonal vertex (10,10) and (100,100) for line P1 (5,120) and P2 (80,7) using Liang-Barsky line clipping method.

Given: P1(5,120), P2(80,7); window xmin = 10, ymin = 10, xmax = 100, ymax = 100.

Parametric line: x = x1 + u·Δx, y = y1 + u·Δy, 0 ≤ u ≤ 1. Here Δx = 80 − 5 = 75, Δy = 7 − 120 = −113.

p1 = −Δx = −75    q1 = x1 − xmin = −5      (left)
p2 =  Δx =  75    q2 = xmax − x1 = 95      (right)
p3 = −Δy =  113   q3 = y1 − ymin = 110     (bottom)
p4 =  Δy = −113   q4 = ymax − y1 = −20     (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−75−5entering, u = 0.067
right7595leaving, u = 1.267
bottom113110leaving, u = 0.9735
top−113−20entering, u = 0.177

u1 = max(0, entering values) = 0.177, u2 = min(1, leaving values) = 0.9735.

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

x1' = x1 + u1·Δx = 5 + 0.177×75 = 18.27
y1' = y1 + u1·Δy = 120 + 0.177×(−113) = 100
x2' = x1 + u2·Δx = 5 + 0.9735×75 = 78.01
y2' = y1 + u2·Δy = 120 + 0.9735×(−113) = 10

Answer: the clipped line is from (18.27, 100) to (78.01, 10).

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Graphics chapter 3 questions →