---
title: "Cohen-Sutherland: two lines vs window A-D"
subject: "Computer Graphics"
chapter: 3
key: "semester_5/computer_graphics:cohen-sutherland-two-lines-window-a"
source: https://www.bctengineer.com/q/semester_5/computer_graphics/cohen-sutherland-two-lines-window-a
site: BCT Engineering
---

# Cohen-Sutherland: two lines vs window A-D

Computer Graphics · Chapter 3: Two –Dimensional Transformations

- Asked in: 2081 Chaitra (new course), 4 marks
- Video: [Cohen Sutherland Line Clipping Example  | CG | Computer Graphics | Lec-35 | Bhanu priya](https://www.youtube.com/watch?v=21drINjp2dg) — Education 4u
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_5/computer_graphics/cohen-sutherland-two-lines-window-a
- Whole chapter: https://www.bctengineer.com/md/semester_5/computer_graphics/chapter-3

## Question

Use the Cohen-Sutherland line clipping algorithm to clip two lines P1(40,50) - P2(75,45) and P3(70,20) - P4(100,10) against a window A (50,10), B (80,10), C (80,40) and D (50,40).

## Short answer

Line P1(40,50)-P2(75,45) is above the window and rejected. Line P3(70,20)-P4(100,10) is partly outside; after clipping it becomes (70,20)-(80,16.67).

## Answer

**Window:** A(50,10), B(80,10), C(80,40), D(50,40), so xmin = 50, ymin = 10, xmax = 80, ymax = 40.

Region code (T B R L): bit 1 = 1 if x < xmin, bit 2 = 1 if x > xmax, bit 3 = 1 if y < ymin, bit 4 = 1 if y > ymax. Slope m = (y2 − y1)/(x2 − x1); intersections: y = y1 + m(x − x1) with a vertical edge, x = x1 + (y − y1)/m with a horizontal edge.

**Line 1:** P1(40, 50), P2(75, 45)

Region codes (T B R L): P1 = 1001, P2 = 1000.

```text
P1=(40,50) code 1001; P2=(75,45) code 1000
Logical AND of codes = 1000 (not 0000): reject
```

Both end points are above the window, so the line is rejected (completely outside the window).

**Line 2:** P3(70, 20), P4(100, 10), m = −10/30 = −1/3

Region codes (T B R L): P3 = 0000, P4 = 0010.

```text
P3=(70,20) code 0000; P4=(100,10) code 0010
Clip P4 against x = xmax = 80: new point (80,16.67)
P3=(70,20) code 0000; P4=(80,16.67) code 0000
Both codes 0000: accept
```

Clipped line: (70, 20) to (80, 16.67).

**Answer:** the line P1P2 is rejected, and the line P3P4 is clipped to (70, 20) - (80, 16.67).

## Check yourself

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

1. What are the codes of P1(40,50) and P2(75,45) for window 50-80 by 10-40?
   A. 0001 and 0000
   B. 1000 and 1000
   C. 1001 and 1000
   D. 0101 and 0100
   Answer: C. Both are above, and P1 is also left of the window. (Key point: Region codes)

2. Why is line P1P2 rejected?
   A. The OR of codes is 0000
   B. It is horizontal
   C. It crosses the window
   D. The AND of codes is nonzero
   Answer: D. A common outside bit means the line is completely on one side. (Key point: Rejection)

3. Where does P3P4 get clipped at x = 80?
   A. (80, 16.67)
   B. (80, 10)
   C. (80, 20)
   D. (100, 10)
   Answer: A. Slope is -1/3, so y = 20 - 10/3 = 16.67. (Key point: Clipping)

## Related in Computer Graphics

- [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×
- [Cohen-Sutherland: (0,120)-(130,5)](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Acohen-sutherland-p1-0-120) — 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

## 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
- [Conductor selection, 100 MW 70 km 132 kV](https://www.bctengineer.com/question.md?key=semester_8%2Ftransmission_and_distribution_system_design%3Aconductor-selection-100mw-70km-132kv) — Transmission and Distribution System Design, chapter 4
