---
title: "Liang-Barsky: (-2,2)-(45,40)"
subject: "Computer Graphics"
chapter: 3
key: "semester_5/computer_graphics:liang-barsky-neg2-2-45-40"
source: https://www.bctengineer.com/q/semester_5/computer_graphics/liang-barsky-neg2-2-45-40
site: BCT Engineering
---

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

Computer Graphics · Chapter 3: Two –Dimensional Transformations

- Asked in: 2070 Chaitra, 6 marks
- Video: [Liang Barsky Line Clipping Algorithm Solved Problem 1](https://www.youtube.com/watch?v=AIX4GZkAvt0) — Md. Ebrahim Hossain
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_5/computer_graphics/liang-barsky-neg2-2-45-40
- Whole chapter: https://www.bctengineer.com/md/semester_5/computer_graphics/chapter-3

## Question

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).

## 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).

## Answer

**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.

```text
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, ...).

| Edge | p | q | u = q/p and remark |
|---|---|---|---|
| left | −47 | −4 | entering, u = 0.0851 |
| right | 47 | 37 | leaving, u = 0.7872 |
| bottom | −38 | −3 | entering, u = 0.0789 |
| top | 38 | 48 | leaving, 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.

```text
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).**

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What are p3 and q3 for the bottom edge (P1(-2,2), ymin=5)?
   A. 38 and 3
   B. -38 and -3
   C. -38 and 3
   D. 38 and -3
   Answer: B. p3 = -Δy = -38, q3 = y1 - ymin = -3. (Key point: p, q for bottom)

2. What is u1 and which edge gives it?
   A. 0.079 from the bottom
   B. 0.787 from the right
   C. 0.0851 from the left edge
   D. 1.263 from the top
   Answer: C. Left gives 0.0851, larger than bottom 0.079. (Key point: u1)

3. What is u2?
   A. 1 from the top
   B. 1.263
   C. 0.085
   D. 0.7872 from the right edge
   Answer: D. The smallest leaving value is the right edge's 0.7872 (top is 1.263, so 1 is not smaller). (Key point: u2)

4. What is the clipped line?
   A. (2, 5.23) to (35, 31.91)
   B. (-2, 2) to (45, 40)
   C. (2, 5) to (35, 50)
   D. (5.23, 2) to (31.91, 35)
   Answer: A. Using u1 and u2 in the parametric equations. (Key point: Result)

## Related in Computer Graphics

- [Liang-Barsky: (6,100)-(60,5)](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Aliang-barsky-6-100-60-5) — Computer Graphics, chapter 3
- [Liang-Barsky: P1(-5,3), P2(15,9)](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Aliang-barsky-0-0-10-10) — Computer Graphics, chapter 3
- [Liang-Barsky: (5,120)-(80,7)](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Aliang-barsky-5-120-80-7) — Computer Graphics, chapter 3
- [Cohen-Sutherland: window (10,10)-(40,40)](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Acohen-sutherland-window-10-40) — Computer Graphics, chapter 3
- [Point clipping and Cohen-Sutherland (5,130)-(50,5)](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Acohen-sutherland-point-clip-5-130) — Computer Graphics, chapter 3
- [Cohen-Sutherland line clipping](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Acohen-sutherland-explain) — Computer Graphics, chapter 3, asked 2×

## Related in other subjects

- [AVL tree for 10 20 30 50 45 40 8 5 3](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Aavl-build-10-20-30) — Data Structure and Algorithm, chapter 6
- [Find x3[n] from X3=X1X2, x1 5-point, x2 4-point](https://www.bctengineer.com/question.md?key=semester_7%2Fdigital_signal_analysis_and_processing%3Adft-product-x3-73s) — Digital Signal Analysis and Processing, chapter 7, asked 3×
- [Two-mass system X1/F, X2/F with F-V analogy](https://www.bctengineer.com/question.md?key=semester_3%2Fcontrol_systems%3Afv-tf-m1-m2-k1b1-k2b2) — Control Systems, chapter 2, asked 3×
- [Practical factors in sampling; sampling interval for X1(t)X2(t)](https://www.bctengineer.com/question.md?key=semester_6%2Fcommunication_systems%3Asampling-practical-x1x2) — Communication Systems, chapter 4
