---
title: "Cohen-Sutherland: window (10,10)-(40,40)"
subject: "Computer Graphics"
chapter: 3
key: "semester_5/computer_graphics:cohen-sutherland-window-10-40"
source: https://www.bctengineer.com/q/semester_5/computer_graphics/cohen-sutherland-window-10-40
site: BCT Engineering
---

# Cohen-Sutherland: window (10,10)-(40,40)

Computer Graphics · Chapter 3: Two –Dimensional Transformations

- Asked in: 2071 Shrawan, 10 marks
- Video: [Cohen Sutherland Line Clipping Algorithm Numerical Explained in Hindi l Computer Graphics](https://www.youtube.com/watch?v=bd9Vd79Q8zA) — 5 Minutes Engineering
- 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-window-10-40
- Whole chapter: https://www.bctengineer.com/md/semester_5/computer_graphics/chapter-3

## Question

Given a clipping window A (10, 10), B (40, 10), C (40, 40) and D (10, 40). Using Cohen-Sutherland line clipping algorithm find region code of each end point of lines P1P2, P3P4 and P5P6 where co-ordinates are P1 (5,15), P2 (25,30), P3 (15,15), P4 (35,30), P5 (5,8) and P6 (40,15). Also find clipped lines using above parameters.

## Short answer

Region codes: P1(5,15)=0001, P2(25,30)=0000, P3(15,15)=0000, P4(35,30)=0000, P5(5,8)=0101, P6(40,15)=0000. P1P2 clipped to (10,18.75)-(25,30); P3P4 entirely inside; P5P6 clipped to (15,10)-(40,15).

## Answer

**Window:** xmin = 10, ymin = 10, xmax = 40, 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.

Region codes (T B R L) of the end points:

| Point | x < 10 (L) | x > 40 (R) | y < 10 (B) | y > 40 (T) | Code |
|---|---|---|---|---|---|
| P1 (5,15) | yes | no | no | no | 0001 |
| P2 (25,30) | no | no | no | no | 0000 |
| P3 (15,15) | no | no | no | no | 0000 |
| P4 (35,30) | no | no | no | no | 0000 |
| P5 (5,8) | yes | no | yes | no | 0101 |
| P6 (40,15) | no | no | no | no | 0000 |

(P6 lies on the right edge x = 40, which counts as inside.)

**Line P1P2:** P1(5, 15), P2(25, 30), m = 15/20 = 0.75

Region codes (T B R L): P1 = 0001, P2 = 0000.

```text
P1=(5,15) code 0001; P2=(25,30) code 0000
Clip P1 against x = xmin = 10: new point (10,18.75)
P1=(10,18.75) code 0000; P2=(25,30) code 0000
Both codes 0000: accept
```

Clipped line: (10, 18.75) to (25, 30).

**Line P3P4:** P3(15, 15), P4(35, 30)

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

```text
P3=(15,15) code 0000; P4=(35,30) code 0000
Both codes 0000: accept
```

Clipped line: (15, 15) to (35, 30).

**Line P5P6:** P5(5, 8), P6(40, 15), m = 7/35 = 0.2

Region codes (T B R L): P5 = 0101, P6 = 0000.

```text
P5=(5,8) code 0101; P6=(40,15) code 0000
Clip P5 against x = xmin = 10: new point (10,9)
P5=(10,9) code 0100; P6=(40,15) code 0000
Clip P5 against y = ymin = 10: new point (15,10)
P5=(15,10) code 0000; P6=(40,15) code 0000
Both codes 0000: accept
```

Clipped line: (15, 10) to (40, 15).

**Answer:**
- P1P2: partly outside; clipped to (10, 18.75) - (25, 30).
- P3P4: both codes 0000, so it is completely inside and accepted as (15,15) - (35,30).
- P5P6: codes 0101 and 0000, AND = 0000, so it is clipped (twice) to (15, 10) - (40, 15).

## Check yourself

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

1. With window 10-40 by 10-40, what is the code of P5(5,8)?
   A. 1010
   B. 0001
   C. 0101
   D. 0100
   Answer: C. x < 10 gives left and y < 10 gives bottom, so 0101. (Key point: Region code)

2. Why is P3P4 accepted without clipping?
   A. It has a positive slope
   B. The AND is nonzero
   C. It passes through the center
   D. Both end points have code 0000
   Answer: D. Both ends inside means the line is wholly inside. (Key point: Trivial accept)

3. Where is P1(5,15) of line P1P2 clipped?
   A. (10, 18.75)
   B. (10, 10)
   C. (15, 18.75)
   D. (5, 18.75)
   Answer: A. At x = 10, y = 15 + 0.75*5 = 18.75. (Key point: Clipping)

4. Why is P5P6 not rejected even though P5 is outside?
   A. P6 is on the edge
   B. The AND of the codes (0101 and 0000) is 0000
   C. Its slope is small
   D. P5 is the start point
   Answer: B. Only if the AND is nonzero is a line rejected; here it is 0000 so clipping continues, giving (15,10)-(40,15). (Key point: Trivial reject)

## Related in Computer Graphics

- [Cohen-Sutherland: two lines vs window A-D](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Acohen-sutherland-two-lines-window-a) — 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×
- [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
- [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
- [Bresenham: line (25,20) to (15,10)](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Adigitize-line-25-20-15-10) — Computer Graphics, chapter 2
