Example of Liang-Barsky Line Clipping

Let P1 (-1, -2), P2 (2, 4)

XL = 0, XR = 1, YB = 0, YT = 1

dx = 2 - (-1) = 3 dy = 4 - (-2) = 6

P1 = -dx = -3 q1 = x1 - XL = -1 - 0 = -1 q1 / P1 = 1/3

P2 = dx = 3 q2 = XR - x1 = 1 - (-1) = 2 q2 / P2 = 2/3

P3 = -dy = -6 q3 = y1 - YR = -2 q3 / P3 = 1/3

P4 = dy = 6 q4 = YT - y1 = 3 q4 / P4 = 1/2

for (Pi < 0) t1="MAX" ( 1 / 3, 1 / 3, 0 )="1" / 3

for (Pi > 0) t2 = MIN ( 2 / 3, 1 / 2, 1 ) = 1 / 2

Since t1 < t2 there is a visible section

compute new endpoints

t1 = 1 / 3 x1' = x1 + dx . t1 = -1 + (3 . 1 / 3) = 0

y1' = y1 + dy . t1 = -2 + (6 . 1 / 3) = 0

t2 = 1 / 2 x2' = x1 + dx . t2 = -1 + (3 . 1 / 2) = 1 / 2

y2' = y1 + dy . t2 = -1 + (6 . 1 / 2) = 1

 


Go back to previous screen
HyperGraph Table of Contents.
HyperGraph Home page.

Last changed May 13, 1998, G. Scott Owen, owen@siggraph.org