The Liang-Barsky line clipping algorithm uses the parametric equation of

2016

The Liang-Barsky line clipping algorithm uses the parametric equation of a line from \((x_{1} , y_{1} )\) to \((x_{2} , y_{2} )\) along with its infinite extension which is given as :

\(x = x_{1} + \Delta x.u\)

\(y = y_{1} + \Delta y.u\)

Where \(\Delta x = x_{2} – x_{1} , \Delta y = y_{2} – y_{1}\), and \(𝑢\) is the parameter with \(0 \leq u \leq 1\). A line \(𝐴𝐵\) with end points \(𝐴(–1,7)\) and \(𝐵(11,1)\) is to be clipped against a rectangular window with \(x_{min} = 1, x_{max} = 9, y_{min} = 2\), and \(y_{max} = 8\). The lower and upper bound values of the parameter u for the clipped line using Liang-Barsky algorithm is given as :

  1. A.

    \((0, \frac{2}{3})\)

  2. B.

    \(\left(\frac{1}{6},\frac{5}{6}\right)\)

  3. C.

    \((0, \frac{1}{3})\)

  4. D.

    \((0, 1)\)

Attempted by 42 students.

Show answer & explanation

Correct answer: B

Key idea: apply the Liang–Barsky tests using the parametric line and update the entering and leaving parameter bounds.

Given endpoints A(-1, 7) and B(11, 1): Δx = 12, Δy = -6. Window: xmin = 1, xmax = 9, ymin = 2, ymax = 8.

  • Left edge (x >= xmin): p = -Δx = -12, q = x1 - xmin = -2, r = q/p = 1/6.

  • Right edge (x <= xmax): p = Δx = 12, q = xmax - x1 = 10, r = q/p = 5/6.

  • Bottom edge (y >= ymin): p = -Δy = 6, q = y1 - ymin = 5, r = q/p = 5/6.

  • Top edge (y <= ymax): p = Δy = -6, q = ymax - y1 = 1, r = q/p = -1/6.

Apply the Liang–Barsky updates starting with u1 = 0 (enter) and u2 = 1 (leave):

  • Left edge: p < 0 → entering, u1 = max(0, 1/6) = 1/6.

  • Right edge: p > 0 → leaving, u2 = min(1, 5/6) = 5/6.

  • Bottom edge: p > 0 → leaving, u2 = min(5/6, 5/6) = 5/6.

  • Top edge: p < 0 → entering, u1 = max(1/6, -1/6) = 1/6.

Conclusion: the final clipped parameter bounds are u = 1/6 to u = 5/6, so the correct pair is (1/6, 5/6).

Explore the full course: Dsssb Tgt Computer Science Paper 2