---
title: "Scan-line method of visible surface"
subject: "Computer Graphics"
chapter: 7
key: "semester_5/computer_graphics:scan-line-visible-surface"
source: https://www.bctengineer.com/q/semester_5/computer_graphics/scan-line-visible-surface
site: BCT Engineering
---

# Scan-line method of visible surface

Computer Graphics · Chapter 7: Visible Surface Determination

- Asked in: 2071 Shrawan, 10 marks; 2075 Asoj, 8 marks; 2074 Asoj, 4 marks (asked 3 times)
- Video: [Scanline method for visual surface detection](https://www.youtube.com/watch?v=stIq9P48VG8) — Shaikh Nikhat Fatma Mumtaz Husain
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_5/computer_graphics/scan-line-visible-surface
- Whole chapter: https://www.bctengineer.com/md/semester_5/computer_graphics/chapter-7

## Question

Describe the scan-line method to determine visible surfaces (lines) of an object, with example.

## Short answer

The scan-line method processes each scan line from top to bottom, tracking active edges and polygon in/out flags. Spans between edge intersections are filled with the polygon's color; if multiple polygons are active, their depths are computed and the nearest is chosen.

## Answer

The **scan-line method** is an image-space method that extends the polygon scan-fill algorithm. Visibility is decided one scan line at a time, from top to bottom, for all polygons that cross that scan line.

**Data structures**
- **Edge table:** each edge's end points, slope and the polygon it belongs to.
- **Polygon table:** plane coefficients, colour, and an in/out **flag** for each polygon.
- **Active edge list:** the edges crossed by the current scan line, sorted by x.

**Algorithm**
```text
for each scan line y (top to bottom):
    update the active edge list (add/delete edges, update x)
    sort the intersections by x
    for each span between successive intersections:
        - flip the in/out flag of the polygon whose edge is crossed
        - if only one polygon flag is "in":  fill the span with its colour
        - if several flags are "in":  compute the depth of each polygon
              (z = (-Ax - By - D)/C) in the span; fill with the
              nearest polygon's colour
        - if none is "in": use the background colour
```

**Example.** Two overlapping polygons S1 and S2 (S1 is in front). The scan line crosses edges at a < b < c < d; S1 covers a to c and S2 covers b to d.

```text
 scan line y:   a=========c              S1 flag IN from a to c
                     b=========d         S2 flag IN from b to d

 a-b : only S1 is IN       -> colour S1
 b-c : S1 and S2 are IN    -> compare depths, S1 nearer -> colour S1
 c-d : only S2 is IN       -> colour S2
```

For non-intersecting surfaces, the depth needs to be computed only once, at the start of the overlap. If surfaces intersect, the span is split at the intersection point. Coherence between successive scan lines (edge intersections change very little from one scan line to the next) speeds up the method.

## Check yourself

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

1. The scan-line method decides visibility how?
   A. Pixel by pixel using a full depth buffer
   B. One scan line at a time, for all polygons crossing it
   C. By sorting whole objects by depth
   D. By removing back faces only
   Answer: B. It extends polygon scan-fill, handling each scan line top to bottom. (Key point: Scan-line basis)

2. What happens to a polygon's flag when a scan line crosses one of its edges?
   A. It is permanently set to in
   B. It is reset for all polygons
   C. The flag toggles between in and out
   D. It is ignored until the next scan line
   Answer: C. Crossing an edge enters or leaves the polygon, so the flag flips. (Key point: In/out flag)

3. In a span where several polygons are flagged in, what is done?
   A. Compute each polygon's depth and fill with the nearest polygon's colour
   B. Fill with the average colour
   C. Fill with the first polygon in the table
   D. Fill with the background colour
   Answer: A. Depth z = (-Ax - By - D)/C is compared and the nearest wins. (Key point: Overlap span)

4. What colour fills a span where no polygon flag is in?
   A. Colour of the previous polygon
   B. Black always
   C. Colour of the nearest edge
   D. Background colour
   Answer: D. No surface covers it, so the background shows. (Key point: Span with no polygon)

## Related in Computer Graphics

- [Compare Z-buffer, A-buffer; scan-line](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Acompare-z-a-buffer-scan-line) — Computer Graphics, chapter 7
- [Image space versus object space methods](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Aimage-space-vs-object-space) — Computer Graphics, chapter 7, asked 9×
- [Reflect object about y=x+1](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Areflect-object-y-x-plus-1) — Computer Graphics, chapter 3
- [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

## Related in other subjects

- [Ruled surface between two lines: points](https://www.bctengineer.com/question.md?key=semester_4%2Fcomputer_aided_design%3Aruled-surface-numerical) — Computer Aided Design, chapter 4
- [Distortionless line and telephone lines](https://www.bctengineer.com/question.md?key=semester_3%2Felectromagnetism%3Adistortionless-line-telephone) — Electromagnetism, chapter 5
- [Magnitude of shortest distance between lines](https://www.bctengineer.com/question.md?key=semester_2%2Fmathematics%3Amagnitude-shortest-distance-between-lines) — Mathematics, chapter 3
- [Painting work on metal surfaces](https://www.bctengineer.com/question.md?key=semester_6%2Fbuilding_technology%3Apainting-metal) — Building Technology, chapter 9, asked 2×
