Skip to main content

Liang-Barsky: P1(-5,3), P2(15,9)

Short answer

For line (-5,3)-(15,9) with window (0,0)-(10,10), Liang-Barsky yields u1=0.25, u2=0.75. Clipped endpoints are (0,4.5) and (10,7.5).

Clip the line P1P2 with P1(-5,3) and P2(15,9) with clip window having diagonal coordinate (0,0) and (10,10) using Liang-Barsky line clipping method.

Given: P1(−5,3), P2(15,9); window xmin = 0, ymin = 0, xmax = 10, ymax = 10.

Parametric line: x = x1 + u·Δx, y = y1 + u·Δy, 0 ≤ u ≤ 1. Here Δx = 15 − (−5) = 20, Δy = 9 − 3 = 6.

p1 = −Δx = −20   q1 = x1 − xmin = −5     (left)
p2 =  Δx =  20   q2 = xmax − x1 = 15     (right)
p3 = −Δy = −6    q3 = y1 − ymin = 3      (bottom)
p4 =  Δy =  6    q4 = ymax − y1 = 7      (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−20−5entering, u = 0.25
right2015leaving, u = 0.75
bottom−63entering, u = −0.5
top67leaving, u = 1.167

u1 = max(0, entering values) = 0.25, u2 = min(1, leaving values) = 0.75.

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

x1' = x1 + u1·Δx = −5 + 0.25×20 = 0
y1' = y1 + u1·Δy = 3 + 0.25×6 = 4.5
x2' = x1 + u2·Δx = −5 + 0.75×20 = 10
y2' = y1 + u2·Δy = 3 + 0.75×6 = 7.5

Answer: the clipped line is from (0, 4.5) to (10, 7.5).

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Graphics chapter 3 questions →