Unit 1: Introduction [6 Hours]
This unit lays the foundation of Computer Graphics: why it matters, what hardware draws an image to your screen, and the core algorithms that turn mathematical shapes (lines, circles, ellipses) into actual pixels. The scan conversion and clipping algorithms here are the most exam-heavy part of this unit and of the subject as a whole, expect numerical, step-by-step questions on Bresenham's Line, Midpoint Circle, and Cohen-Sutherland clipping in particular.
Tested Topics
- DDA line drawing algorithm — 2× (2023, 2022)
- Flood fill algorithm — 2× (2024, 2022)
- Midpoint circle drawing algorithm — 2× (2024, 2022)
- Beam penetration vs Shadow mask methods — 1× (2023)
- Boundary fill vs Flood fill algorithms (differentiation) — 1× (2023)
- Bresenham's line drawing algorithm (decision parameter) — 1× (2024)
- Computer Graphics vs Image Processing — 1× (2023)
- Horizontal/vertical retrace of electron beam — 1× (2022)
- Pixel and resolution — 1× (2024)
- Random scan display system architecture — 1× (2022)
- Raster scan display system (working) — 1× (2023)
- Raster scan vs Vector scan display — 1× (2024)
- Scan conversion (definition) — 1× (2024)
- Video controller in raster scan system — 1× (2024)
1.1 Advantage of Computer Graphics and Areas of Application
Core Definition
Computer Graphics is the field of computer science concerned with generating, manipulating, and displaying images and visual data using a computer.
Computer graphics is simply how a computer turns numbers and instructions into pictures you can see on a screen.
Detailed Explanation
Computer graphics matters because humans process visual information far faster than raw text or numbers. A chart explains a trend instantly; a thousand rows of numbers do not. This is why graphics is used everywhere modern computing touches: design, entertainment, science, and communication.
Advantages
Better understanding → visual data (charts, diagrams, 3D models) is grasped faster than raw numbers.
Improved communication → designs, simulations, and presentations communicate ideas without language barriers.
Realistic simulation → allows training and testing in safe, virtual environments (flight simulators, surgery practice).
Creative and entertainment value → enables movies, games, and animation that would be impossible or extremely costly to film physically.
Design efficiency → CAD tools let engineers test and modify designs digitally before physical production, saving cost and time.
Areas of Application
| Domain | Use of Computer Graphics |
|---|---|
| CAD (Computer-Aided Design) | Designing buildings, machine parts, circuits before manufacturing |
| Entertainment | Animated films, video games, special effects |
| Education and Training | Simulators (flight, medical), interactive learning visuals |
| Presentation Graphics | Charts, graphs, slideshows for business and research |
| Image Processing | Editing, enhancing, or analyzing photographs and scans |
| GUI (Graphical User Interface) | Icons, windows, buttons that let users interact with software visually |
| Art and Animation | Digital painting, 2D/3D animation production |
Summary
- Computer graphics converts data and instructions into visual images.
- It improves understanding, communication, and design efficiency over text/numbers alone.
- Major application areas: CAD, entertainment, education, presentation graphics, image processing, GUI, art.
One-Liner Revision
Computer graphics turns data into visuals, used across CAD, entertainment, education, GUIs, and image processing.
1.2 Hardware and Software for Computer Graphics
Core Definition
Graphics hardware refers to the physical devices, input, display, and hard copy, used to create and output images, while graphics software refers to the programs and packages used to generate and manipulate those images.
Hardware is the physical equipment (screen, printer, mouse); software is the program that decides what gets drawn and how.
Detailed Explanation
Every graphics system needs three categories of hardware working together: devices to input commands or drawings (mouse, scanner, digitizer), a device to display the result temporarily (a monitor), and devices to produce a permanent, hard copy output (printers, plotters). Software then sits on top, ranging from low-level graphics libraries to full applications like CAD or paint programs.
Hard Copy Devices
| Type | Working Principle | Example |
|---|---|---|
| Impact printers | Strike an ink ribbon physically against paper | Dot-matrix printer |
| Non-impact printers | Use heat, ink spray, or laser/toner with no physical striking | Inkjet, laser printer |
| Plotters | Move a pen (or print head) across paper to draw precise vector lines | Used for engineering drawings, maps |
Display Technologies
CRT (Cathode Ray Tube) → fires an electron beam at a phosphor-coated screen; the beam's position and intensity are controlled to light up phosphor dots, the basis for both random-scan and raster-scan displays covered next.
LCD (Liquid Crystal Display) → uses liquid crystals that twist to block or pass light from a backlight, controlled per pixel; thinner and more power-efficient than CRT.
Plasma and LED displays [verify] → use charged gas (plasma) or light-emitting diodes (LED) directly as the light source per pixel, offering high brightness and contrast.
Graphics Software Categories
General programming packages → provide graphics functions as a library (e.g., OpenGL) that a programmer calls from a language like C++.
Special-purpose application packages → ready-made software for specific tasks: CAD tools, paint programs, animation software, where the user does not write code, just uses the interface.
Common Mistake
Students often confuse a plotter with a regular printer. A plotter draws using continuous pen movement along vector paths (ideal for precise line drawings like blueprints), while a printer builds an image from a grid of dots or pixels.
Summary
- Graphics hardware spans input devices, display devices, and hard copy devices.
- Hard copy devices include impact printers, non-impact printers, and plotters.
- Display technologies include CRT, LCD, and plasma/LED, each with a different method of producing light per pixel.
- Graphics software ranges from low-level programming libraries to ready-made application packages.
One-Liner Revision
Graphics hardware (input, display, hard copy) and graphics software (libraries, applications) together let a system create and output images.
1.3 Random Scan Display System, Video Controller, Random Scan Display Processor
Core Definition
A random scan display system (vector display) draws an image by directing the electron beam only along the actual line paths that make up the picture, rather than scanning the entire screen, and a random scan display processor is the dedicated hardware that repeatedly feeds those line-drawing commands to the beam to keep the image refreshed.
Instead of "painting" the whole screen row by row, a random scan display draws an image the way you would draw with a pen: it moves directly from point to point only where a line actually exists.
Detailed Explanation
In a random scan (vector) system, the picture is stored as a set of line-drawing commands, often called a display file or refresh display file, listing the endpoints of every line segment in the image. The display processor cycles through this file and steers the electron beam directly between those endpoints, lighting the phosphor only along actual line paths. Because curved or complex shapes still need to be turned into many short straight line segments, random scan systems are best suited to line drawings such as engineering schematics, rather than realistic, shaded images.
Video Controller
A video controller is the hardware component that manages how an image is continuously sent from memory to the display, refreshing the screen many times per second so the picture appears stable instead of flickering. It works by repeatedly cycling through the stored picture information (line commands in a random scan system, or pixel values in a raster system, covered in 1.4) and converting that information into the deflection or intensity signals the screen hardware needs at every refresh cycle.
Random Scan Display Processor (Architecture)
The random scan display processor sits between the CPU and the CRT, and operates in a repeating cycle:
Step 1 → The CPU sends drawing commands (e.g., "draw line from A to B") to the display processor.
Step 2 → The display processor stores these commands in the refresh display file in memory.
Step 3 → The processor continuously reads through the display file, command by command, converting each into the analog deflection voltages needed to move the electron beam.
Step 4 → The beam is moved directly from one line's start point to its end point, lighting the phosphor only along that path.
Step 5 → Once the entire display file has been processed, the cycle repeats from the top, refreshing the whole image roughly 30 to 60 times per second so it appears continuously visible to the human eye.
Let's Break It Down
A random scan system is like a laser pointer tracing the outline of a drawing on a wall, over and over, so fast that your eye sees a stable picture instead of a moving dot. It only ever moves along the lines that exist; it never wastes time sweeping across empty space.
Common Mistake
Students often think the video controller and the random scan display processor are the same thing. The video controller is the general hardware managing the refresh cycle (used in both random scan and raster systems), while the random scan display processor is the specific implementation that handles vector/line-drawing commands rather than pixel data.
Test Yourself
- Why is a random scan system well suited to line drawings but poorly suited to realistic, shaded images?
- What does the random scan display processor repeatedly cycle through to keep the image refreshed?
Answers: 1) It only draws along actual line paths; shaded, filled, or photo-realistic images do not naturally reduce to a manageable set of line segments, so the technique fits outline-style drawings best.
2) The refresh display file, a stored list of line-drawing commands describing the image.
Summary
- A random scan display draws only along actual line paths, using a stored display file of line commands.
- The video controller manages the general refresh cycle from stored picture data to the screen.
- The random scan display processor specifically interprets and redraws vector line commands repeatedly to refresh the image.
One-Liner Revision
Random scan systems draw only along line paths from a stored display file, refreshed continuously by the display processor.
1.4 Raster Graphics
Core Definition
Raster graphics (raster scan) is a display technique where the electron beam sweeps across the entire screen row by row, lighting up individual pixels based on values stored in a frame buffer, building the full image like a grid rather than a set of lines.
Instead of drawing only the lines, a raster display lights up every single dot on the screen, row after row, deciding for each dot whether it should be on, off, or a certain color, based on data stored in memory.
Detailed Explanation
A raster scan display stores the entire image as a grid of pixel values in a memory area called the frame buffer (or refresh buffer). The video controller reads this frame buffer row by row, left to right, top to bottom, and converts each pixel's stored value into the correct intensity or color signal for the screen, repeating roughly 60 times a second. Because every pixel on the screen is touched on every refresh, raster systems can represent filled areas, shading, and photographic detail far better than random scan systems, which is why nearly all modern displays (LCD, LED) use raster-based principles.
Key Concepts
Pixel → the smallest controllable point of an image, each holding a color/intensity value.
Frame buffer → the memory area storing the color value of every pixel on the screen for the current frame.
Resolution → the number of pixels in the horizontal and vertical directions (e.g. 1920×1080); higher resolution means finer detail.
Refresh rate → how many times per second the entire frame buffer is redrawn to the screen, measured in Hz.
Interlaced scanning → refreshes odd-numbered scan lines first, then even-numbered lines, in alternate passes, reducing the data rate needed per pass at the cost of potential flicker.
Non-interlaced (progressive) scanning → refreshes every line in a single top-to-bottom pass, giving a steadier image.
Raster Scan vs Random Scan
| Aspect | Raster Scan | Random Scan |
|---|---|---|
| Drawing method | Scans every pixel, row by row, across the whole screen | Draws only along actual line paths |
| Storage | Frame buffer (pixel values) | Display file (line-drawing commands) |
| Best for | Realistic images, shading, filled areas, photographs | Line drawings, wireframes, schematics |
| Refresh independent of complexity? | Yes, refresh time depends only on resolution | No, refresh time grows with number of line segments |
Test Yourself
- Why does a raster system's refresh time stay constant regardless of how complex the image is, while a random scan system's refresh time does not?
- What is stored in a frame buffer?
Answers: 1) A raster system always scans the same fixed number of pixels for a given resolution, while a random scan system must redraw every line segment, so a more complex image with more lines takes longer to refresh.
2) The color/intensity value of every pixel that makes up the current screen image.
Summary
- Raster graphics builds an image pixel by pixel, row by row, from a frame buffer.
- Resolution and refresh rate determine image detail and how often the screen is redrawn.
- Interlaced scanning refreshes alternate lines in two passes; non-interlaced refreshes all lines in one pass.
- Raster scan suits realistic, filled, shaded images far better than random scan.
One-Liner Revision
Raster graphics draws the entire screen pixel by pixel from a frame buffer, making it ideal for filled, realistic images.
1.5 Scan Conversion Algorithms (Line, Circle, Ellipse)
Core Definition
Scan conversion is the process of converting a mathematically defined shape, like a line, circle, or ellipse, into the discrete set of pixel positions on a raster grid that best approximate that shape.
A line or circle drawn on paper is a smooth, continuous curve, but a screen only has discrete dots. Scan conversion algorithms decide exactly which dots to light up so the result looks like that smooth shape.
Detailed Explanation
Because a pixel grid has no true diagonal or curved lines, any non-horizontal/vertical line or curve must be approximated using the nearest pixels at each step. The challenge solved by these algorithms is doing this approximation accurately and fast, using only integer arithmetic where possible, since floating-point operations are slower for hardware to compute repeatedly.
DDA (Digital Differential Analyzer) Line Algorithm
The DDA algorithm draws a line by calculating successive points using the line's slope, incrementing one coordinate by 1 and computing the other using floating-point addition.
Step 1 → Compute dx = x1 - x0 and dy = y1 - y0.
Step 2 → Let steps = max(|dx|, |dy|) (the larger of the two determines how many points to plot).
Step 3 → Compute increments xinc = dx / steps and yinc = dy / steps.
Step 4 → Starting at (x0, y0), repeatedly add xinc to x and yinc to y, rounding each to the nearest integer to plot the pixel, for steps iterations.
DDA is simple to understand but uses floating-point addition and rounding at every single step, which makes it slower than Bresenham's algorithm below; it is mainly taught as a stepping stone toward understanding the more efficient integer-only approach.
Bresenham's Line Algorithm
Bresenham's algorithm draws a line using only integer arithmetic, by tracking a decision parameter that determines whether the next pixel should move straight or diagonally, avoiding rounding and division entirely. The version below assumes the line has a slope between 0 and 1, with x0 < x1 and y0 < y1 (the most commonly taught case).
Step 1 → Compute dx = x1 - x0, dy = y1 - y0.
Step 2 → Compute the initial decision parameter: p0 = 2dy - dx.
Step 3 → At each step, increment x by 1. If pk < 0, keep the same y, and the next parameter is pk+1 = pk + 2dy. If pk >= 0, increment y by 1 as well, and the next parameter is pk+1 = pk + 2dy - 2dx.
Step 4 → Repeat Step 3 until x reaches x1.
The decision parameter is a clever shortcut: it represents (scaled and shifted) which of the two candidate pixels, directly across or diagonally across, lies closer to the true mathematical line, all without ever computing a square root or a fraction.
Worked Example: Line from (20,10) to (30,18)
dx = 10, dy = 8. p0 = 2(8) - 10 = 6. Constants used at each step: add 2dy = 16 when p < 0, or add 2dy - 2dx = -4 when p >= 0.
| k | pk | Decision | Plotted Point | pk+1 |
|---|---|---|---|---|
| 0 | 6 | p≥0 → y+1 | (21,11) | 2 |
| 1 | 2 | p≥0 → y+1 | (22,12) | -2 |
| 2 | -2 | p<0 → same y | (23,12) | 14 |
| 3 | 14 | p≥0 → y+1 | (24,13) | 10 |
| 4 | 10 | p≥0 → y+1 | (25,14) | 6 |
| 5 | 6 | p≥0 → y+1 | (26,15) | 2 |
| 6 | 2 | p≥0 → y+1 | (27,16) | -2 |
| 7 | -2 | p<0 → same y | (28,16) | 14 |
| 8 | 14 | p≥0 → y+1 | (29,17) | 10 |
| 9 | 10 | p≥0 → y+1 | (30,18) | — |
The line correctly ends at (30,18), matching the given endpoint, confirming the algorithm worked correctly.
Midpoint Circle Algorithm
The midpoint circle algorithm plots a circle using its 8-way symmetry: it only calculates points for one octant (45 degrees of the circle, typically from the top point to the 45° diagonal), then mirrors those points into the other 7 octants, since a circle is symmetric across both axes and both diagonals.
Step 1 → Start at (x0, y0) = (0, r), the topmost point of the circle.
Step 2 → Compute the initial decision parameter: p0 = 1.25 - r (often rounded to 1 - r for integer radii).
Step 3 → At each step, always increment x by 1. If pk < 0, keep the same y, and the next point's parameter is pk+1 = pk + 2xk+1 + 1. If pk >= 0, also decrement y by 1, and the next parameter is pk+1 = pk + 2xk+1 + 1 - 2yk+1.
Step 4 → Stop once x equals y (the 45° boundary); for each calculated (x,y), plot all 8 symmetric points: (±x,±y) and (±y,±x).
Worked Example: Circle with r = 10
p0 = 1 - 10 = -9, start (0,10).
| k | pk | Decision | Plotted Point | pk+1 |
|---|---|---|---|---|
| 0 | -9 | p<0 → same y | (1,10) | -6 |
| 1 | -6 | p<0 → same y | (2,10) | -1 |
| 2 | -1 | p<0 → same y | (3,10) | 6 |
| 3 | 6 | p≥0 → y-1 | (4,9) | -3 |
| 4 | -3 | p<0 → same y | (5,9) | 8 |
| 5 | 8 | p≥0 → y-1 | (6,8) | 5 |
| 6 | 5 | p≥0 → y-1 | (7,7) | — |
The algorithm stops at (7,7) since x = y here, the 45° boundary. Each point listed is then mirrored into all 8 octants to complete the full circle.
Midpoint Ellipse Algorithm
An ellipse only has symmetry across its two axes (4-way, not 8-way), and its curvature changes differently along its width versus its height, so the algorithm splits the curve into two regions at the point where the slope equals -1.
Region 1 (near the top of the ellipse, where the boundary slope is shallower than -1, x changes faster): step x by 1 each time, decide whether y also decreases.
Region 2 (near the side of the ellipse, where the boundary is steeper than -1, y changes faster): step y by -1 each time, decide whether x also increases.
For an ellipse with semi-axes rx and ry centered at the origin:
Region 1 initial parameter: p1_0 = ry² - rx²·ry + 0.25·rx².
While in Region 1: if p1k < 0, move to (xk+1, yk) with p1k+1 = p1k + 2ry²·xk+1 + ry²; otherwise move to (xk+1, yk-1) with p1k+1 = p1k + 2ry²·xk+1 - 2rx²·yk+1 + ry². Switch to Region 2 once the slope becomes steeper than -1.
Region 2 initial parameter: p2_0 = ry²·(x0+0.5)² + rx²·(y0-1)² - rx²·ry², using the last point from Region 1.
While in Region 2: if p2k > 0, move to (xk, yk-1) with p2k+1 = p2k - 2rx²·yk+1 + rx²; otherwise move to (xk+1, yk-1) with p2k+1 = p2k + 2ry²·xk+1 - 2rx²·yk+1 + rx². Stop when y = 0.
As with the circle, every calculated point is mirrored into the other 3 quadrants, since an ellipse is symmetric across both its major and minor axes.
Let's Break It Down
Drawing a circle or ellipse with the midpoint method is like deciding, at every step, whether your next dot should go "straight" or "diagonally" by checking which choice keeps you closer to the true curve, using only addition and comparison, never a square root. The decision parameter is just a running scorecard of "how far off course am I right now."
Common Mistake
A frequent error is forgetting to mirror points into all symmetric octants/quadrants. The algorithm only computes one-eighth (circle) or one-quarter (ellipse) of the curve directly; the rest must be filled in by symmetry, not recalculated.
Test Yourself
- Why does Bresenham's line algorithm avoid floating-point arithmetic while DDA does not?
- Why does the midpoint circle algorithm only need to compute one octant of points?
Answers: 1) Bresenham's uses an integer decision parameter updated by addition/subtraction of 2dy and 2dx terms, while DDA must add fractional increments (dx/steps, dy/steps) and round at every step.
2) A circle is symmetric across both axes and both diagonals, giving 8-way symmetry, so one octant's points can be mirrored to generate the remaining seven.
Summary
- Scan conversion turns mathematical shapes into the nearest matching pixel positions.
- DDA uses floating-point increments based on slope; simple but slower.
- Bresenham's Line Algorithm uses an integer decision parameter to choose between two candidate pixels at each step.
- Midpoint Circle Algorithm computes one octant using a decision parameter, then mirrors to all 8 octants.
- Midpoint Ellipse Algorithm splits the curve into two regions (by slope) with separate decision parameters, then mirrors to all 4 quadrants.
One-Liner Revision
Scan conversion algorithms (DDA, Bresenham, midpoint circle/ellipse) use slope and decision parameters to pick the closest pixels to a true line or curve, exploiting symmetry wherever possible.
1.6 Area Filling Algorithms (Rectangle, Ellipse)
Core Definition
Area filling is the process of coloring all the pixels that lie inside a closed boundary, such as a rectangle or an ellipse, rather than just drawing the outline.
If scan conversion draws the outline of a shape, area filling is what colors in everything inside that outline, like coloring inside the lines of a drawing.
Detailed Explanation
The general strategy for filling any shape is scan-line filling: for every horizontal row (scan line) that intersects the shape, find where the shape's boundary crosses that row, and color every pixel between those crossing points. The exact way you find those crossing points depends on the shape.
Filling a Rectangle
A rectangle is the simplest case because its boundary is always made of horizontal and vertical lines, so the left and right boundary on every scan line are simply the rectangle's fixed xmin and xmax.
for (y = ymin; y <= ymax; y++)
{
for (x = xmin; x <= xmax; x++)
{
SetPixel(x, y);
}
}This nested loop simply colors every pixel between the rectangle's corners, row by row.
Filling an Ellipse
An ellipse cannot use fixed left/right boundaries because its width changes at every row. The fill uses the same midpoint ellipse boundary points calculated in Section 1.5: for each computed boundary point (x, y), the pixels to fill on that scan line run from -x+x at height y (and mirrored for -y).
// For each (x, y) boundary point computed by the midpoint ellipse algorithm:
for (px = -x; px <= x; px++)
{
SetPixel(centerX + px, centerY + y); // fill upper half row
SetPixel(centerX + px, centerY - y); // fill mirrored lower half row
}This reuses the boundary-tracing work already done for drawing the ellipse outline, instead of recalculating intersections from scratch, making filling and outlining closely connected steps.
Common Mistake
Filling a rectangle and filling an ellipse are not interchangeable techniques. Using a rectangle's fixed-boundary loop on an ellipse will fill its bounding box, not the ellipse itself, including the corner areas outside the curve that should remain unfilled.
Test Yourself
- Why can a rectangle be filled with a simple fixed double loop, but an ellipse cannot?
Answers: 1) A rectangle's left and right boundary (xmin, xmax) never change across rows, while an ellipse's width changes at every row, so its fill boundary must be recalculated per scan line using the curve's actual boundary points.
Summary
- Area filling colors every pixel inside a shape's boundary, using a scan-line approach.
- A rectangle fills with a simple fixed double loop, since its boundaries never change per row.
- An ellipse fills using the boundary points already computed by the midpoint ellipse algorithm, filling between
-xand+xat each computedy.
One-Liner Revision
Area filling colors pixels between a shape's left and right boundary on every scan line, fixed for a rectangle, recalculated per row for an ellipse.
1.7 Clipping: Line Clipping (Cohen-Sutherland Algorithm)
Core Definition
Clipping is the process of determining which portion of a drawing lies inside a defined rectangular clipping window, and discarding or trimming everything outside it. The Cohen-Sutherland algorithm performs line clipping efficiently using a 4-bit region code assigned to each endpoint.
Clipping is like cutting a photo down to fit a picture frame, anything outside the frame's edges gets cut away, and anything crossing an edge gets trimmed exactly at that edge.
Detailed Explanation
Checking every line against every edge with full intersection math is wasteful when most lines are either entirely inside or entirely outside the window. Cohen-Sutherland speeds this up by first assigning each endpoint a 4-bit outcode describing which side(s) of the window it lies outside, allowing instant accept/reject decisions for most lines without any intersection calculation at all.
Region Codes (Outcodes)
The clipping window has four edges: xmin, xmax, ymin, ymax. Each endpoint gets a 4-bit code, ordered Top, Bottom, Right, Left:
Top bit = 1 if y > ymax.
Bottom bit = 1 if y < ymin.
Right bit = 1 if x > xmax.
Left bit = 1 if x < xmin.
A point fully inside the window gets the code 0000.
Algorithm Steps
Step 1 → Compute the outcode for both endpoints of the line.
Step 2 → Trivial accept: if both outcodes are 0000, the entire line is inside, keep it unchanged.
Step 3 → Trivial reject: if the bitwise AND of both outcodes is not 0000, both points lie outside the same edge, the entire line is outside, discard it.
Step 4 → Otherwise, the line needs clipping: pick the endpoint with a non-zero outcode, find which boundary it violates, and compute the exact intersection point of the line with that boundary using the line's parametric equation.
Step 5 → Replace that endpoint with the intersection point, recompute its outcode, and repeat from Step 2 until the line is either trivially accepted or trivially rejected.
Worked Example
Clipping window: xmin=10, ymin=10, xmax=50, ymax=50. Line from P1=(5,40) to P2=(60,20).
Outcode of P1: x=5 < 10 → Left bit set → 0001. Outcode of P2: x=60 > 50 → Right bit set → 0010. AND of codes = 0000, so not a trivial reject; neither is 0000, so not a trivial accept either, meaning the line must actually be clipped.
P1 violates the Left edge (x=10). Using the parametric line equation with dx=55, dy=-20: t = (10-5)/55 ≈ 0.0909, giving y = 40 + 0.0909×(-20) ≈ 38.18. New point: P1' = (10, 38.18), outcode now 0000.
P2 still violates the Right edge (x=50). Recomputing from P1' to P2 with dx=50, dy=-18.18: t = (50-10)/50 = 0.8, giving y = 38.18 + 0.8×(-18.18) ≈ 23.64. New point: P2' = (50, 23.64), outcode now 0000.
Both codes are now 0000 → trivial accept. The clipped line runs from (10, 38.18) to (50, 23.64).
Let's Break It Down
Outcodes work like a postal address sorted into compass directions. If a point's code says "north of the frame," you instantly know it's outside without measuring anything precisely. Only when two points disagree (one north, one inside, say) do you actually need to calculate exactly where the line crosses the frame's edge.
Common Mistake
A common error is assuming that if the bitwise AND of the two outcodes is 0000, the line must be fully inside. It only means the line is not trivially rejectable, the line may still need clipping if either outcode is non-zero.
Test Yourself
- If both endpoints of a line have outcode
0100(Right bit set), what can you immediately conclude using the trivial reject test? - Why does Cohen-Sutherland avoid computing intersections for most lines?
Answers: 1) The AND of 0100 and 0100 is 0100, which is non-zero, so the line is trivially rejected, both points are outside the same (Right) edge, the entire line lies outside the window.
2) The outcode-based trivial accept/reject tests instantly resolve most lines (fully inside or fully outside) with simple comparisons, leaving intersection math only for lines that genuinely cross the window boundary.
Summary
- Clipping keeps only the portion of a drawing inside a defined window.
- Cohen-Sutherland assigns a 4-bit outcode (Top, Bottom, Right, Left) to each line endpoint.
- Trivial accept: both outcodes
0000. Trivial reject: AND of outcodes is non-zero. - Otherwise, the line is clipped step by step at each violated boundary using the parametric line equation.
One-Liner Revision
Cohen-Sutherland uses 4-bit outcodes for instant accept/reject, and computes boundary intersections only for lines that genuinely need trimming.
1.8 Clipping: Circle and Ellipse Clipping
Core Definition
Circle and ellipse clipping determines which portion of a curved boundary lies inside a rectangular clipping window, trimming the curve at the points where it crosses the window's edges.
Just like a line can be cut where it crosses the frame's edge, a circle or ellipse is cut at the points where its round boundary crosses each edge of the clipping window, keeping only the arc that lies inside.
Detailed Explanation
Unlike a line, a circle or ellipse has no single straight intersection formula, since its boundary is curved, but the same accept/reject logic from line clipping still helps reduce unnecessary work before any curve math is done.
Clipping Procedure
Step 1 → Bounding box test: compute the circle or ellipse's bounding rectangle. If this bounding rectangle is entirely inside the clipping window, trivially accept the entire shape with no further computation. If the bounding rectangle is entirely outside the window on one side, trivially reject the entire shape.
Step 2 → If the bounding box partially overlaps the window, find the points where the circle/ellipse boundary equation intersects each of the window's four edge lines, by substituting the edge's fixed x (for vertical edges) or fixed y (for horizontal edges) into the curve's equation and solving for the other coordinate.
Step 3 → Walk along the curve's boundary (using the same scan-conversion points from Section 1.5) and keep only the arc segments whose points satisfy all four window boundary conditions (xmin ≤ x ≤ xmax and ymin ≤ y ≤ ymax) simultaneously.
Step 4 → Discard the arc segments lying outside any of the four edges.
Let's Break It Down
Clipping a circle is like trimming a round cookie to fit inside a square cookie cutter outline drawn on the dough. You don't need to do any cutting if the cookie already fits fully inside or lies entirely outside the outline; you only need careful trimming for the arcs that actually poke past an edge.
Common Mistake
Students sometimes try to apply Cohen-Sutherland's straight-line intersection formula directly to a circle or ellipse. A curved boundary needs the shape's own equation (circle or ellipse equation) solved against each edge, a straight-line formula does not apply to curved boundaries.
Test Yourself
- What is the first quick test used before computing any actual curve-edge intersections?
Answers: 1) The bounding box test: checking whether the shape's bounding rectangle is fully inside (trivial accept) or fully outside (trivial reject) the clipping window before doing any curve intersection math.
Summary
- Circle/ellipse clipping first uses a bounding box test for trivial accept/reject.
- Partial overlaps require solving the curve's own equation against each window edge.
- Only the arc points satisfying all four window boundary conditions are kept.
One-Liner Revision
Circle/ellipse clipping uses a bounding box test first, then solves the curve's equation against window edges to keep only the inside arcs.
1.9 Clipping Polygons (Sutherland-Hodgman Algorithm)
Core Definition
The Sutherland-Hodgman algorithm clips a polygon against a rectangular window by processing the polygon against one window edge at a time, producing a new, smaller polygon after each edge, until all four edges have been applied.
Instead of trying to clip a polygon against all four window edges at once, this algorithm clips against one edge fully first, then feeds that result into clipping against the next edge, like passing dough through four shaping rollers, one side at a time.
Detailed Explanation
A polygon is just a sequence of connected vertices. For each single clipping edge, the algorithm walks through the polygon's vertices in order, comparing each vertex against the previous one, and decides what to keep based on whether each vertex is inside or outside that one edge.
Algorithm Steps (per edge)
For each pair of consecutive vertices S (previous) and P (current), tested against one clipping edge:
Case 1 → If P is inside and S is inside: add P to the output polygon.
Case 2 → If P is inside and S is outside: the edge SP crosses the boundary, so first add the intersection point of SP with the clip edge, then add P.
Case 3 → If P is outside and S is inside: the edge SP crosses the boundary going out, so add only the intersection point of SP with the clip edge (P itself is discarded).
Case 4 → If P is outside and S is outside: add nothing.
This process runs for every vertex pair around the polygon, against the left edge first, then the result is run again against the right edge, then the bottom edge, then the top edge, with the output of each stage becoming the input polygon for the next stage.
Illustrative Example (Single Edge)
Consider clipping a triangle with vertices S=(5,5) (outside, left of xmin=10) and P=(20,5) (inside) against the left edge x=10. This matches Case 2: P is inside, S is outside. The intersection of segment SP with x=10 is computed (here, simply (10,5) since both points share y=5), so the output adds (10,5) first, then (20,5). This same Case 1–4 logic is then repeated for every other vertex pair of the polygon, and then for the remaining three edges in turn, until a fully clipped polygon remains.
Let's Break It Down
Think of Sutherland-Hodgman like passing a paper cutout through four guillotine cutters, one for each side of the frame. After passing through the left cutter, whatever remains goes through the right cutter, then bottom, then top. By the time the shape has passed through all four, only the part that fits inside the frame on every side survives.
Common Mistake
A common error is clipping against all four edges simultaneously in one pass. Sutherland-Hodgman strictly clips against one edge at a time, using the previous edge's output polygon as the next edge's input polygon; skipping this sequencing produces an incorrect result.
Test Yourself
- If vertex S is inside the clip edge and vertex P is outside it, what gets added to the output polygon?
- Why does Sutherland-Hodgman process one edge fully before moving to the next, rather than checking all four edges at once per vertex?
Answers: 1) Only the intersection point of segment SP with the clip edge is added; P itself, being outside, is discarded.
2) Clipping against one edge at a time keeps the inside/outside test simple (a single boundary comparison) and lets each stage's output polygon directly become the next stage's input, which is far simpler than tracking four boundary conditions simultaneously for every vertex.
Summary
- Sutherland-Hodgman clips a polygon against one window edge at a time, in four passes (left, right, bottom, top).
- Each vertex pair is classified into one of four inside/outside cases, deciding whether to keep the vertex, add an intersection point, or discard.
- The output polygon from one edge becomes the input polygon for the next edge.
One-Liner Revision
Sutherland-Hodgman clips a polygon edge by edge, keeping inside vertices, adding intersection points at crossings, and discarding outside vertices.
Exam Questions
- How raster scan display is different from vector scan display? What is the role of video controller in raster scan display system? (2024)
- Define Pixel and resolution. (2024)
- How flood fill algorithm can be used to fill a polygon? Explain. (2024)
- Use the Midpoint Circle drawing Algorithm to draw a circle with a radius of 7 units, centered at (5,5). (2024)
- What is scan conversion? Derive the decision parameter for Bresenham's line drawing algorithm for m<1. (2024)
- Differentiate between beam penetration method and shadow mask method. How does raster scan display system work? (2023)
- How DDA works? Digitize the line segment with the endpoints (15, 25) and (21, 35) using DDA line drawing algorithm. (2023)
- Write short notes on (any two): (c) Computer Graphics Vs. Image Processing (2023)
- Differentiate between boundary fill algorithm and flood fill algorithm in detail. (2023)
- Define horizontal and vertical retrace of electron beam. Explain architecture of random scan display system. (2022)
- How does decision parameter can be used to draw circle? Calculate the points to draw a circle having radius 5 and center has (10, 5) using mid-point circle algorithm. (2022)
- Generate the points between the end points of a line viz. (2, 2) and (9, 6) by using DDA line drawing algorithm. (2022)
- Explain Flood Filled algorithm with its applicability and concept. (2022)
Whole Chapter Summary
- 1.1 Advantages and Applications: computer graphics improves understanding and communication, used across CAD, entertainment, education, and GUIs.
- 1.2 Hardware and Software: input, display, and hard copy hardware (printers, plotters) work alongside graphics software, from libraries to ready-made applications.
- 1.3 Random Scan Systems: draw only along line paths from a stored display file, refreshed by a dedicated display processor.
- 1.4 Raster Graphics: builds the whole screen pixel by pixel from a frame buffer, ideal for realistic, filled images.
- 1.5 Scan Conversion: DDA, Bresenham's Line, and midpoint circle/ellipse algorithms convert mathematical shapes into actual pixel positions.
- 1.6 Area Filling: colors pixels inside a boundary using scan-line filling, fixed for rectangles, boundary-driven for ellipses.
- 1.7 Line Clipping: Cohen-Sutherland uses 4-bit outcodes for fast accept/reject and trims lines at window edges.
- 1.8 Circle/Ellipse Clipping: bounding box test first, then curve-edge intersection for partial overlaps.
- 1.9 Polygon Clipping: Sutherland-Hodgman clips a polygon against one window edge at a time across four passes.
Key Formulas and Points Sheet
| Formula / Rule | Meaning |
|---|---|
DDA: steps = max(|dx|,|dy|); xinc=dx/steps, yinc=dy/steps | Line drawn via floating-point increments per axis |
Bresenham Line: p0 = 2dy - dx | Initial decision parameter for line slope 0–1 |
Bresenham Line update: p<0 → p+2dy; p≥0 → p+2dy-2dx | Chooses same-row vs diagonal pixel |
Midpoint Circle: p0 = 1.25 - r | Initial decision parameter, octant 0–45° |
Midpoint Circle update: p<0 → p+2x+1; p≥0 → p+2x+1-2y | Chooses same-row vs diagonal pixel for circle |
Midpoint Ellipse Region 1: p1_0 = ry² - rx²ry + 0.25rx² | Initial parameter, shallow-slope region |
Midpoint Ellipse Region 2: p2_0 = ry²(x0+0.5)² + rx²(y0-1)² - rx²ry² | Initial parameter, steep-slope region |
| Outcode bits (Cohen-Sutherland) | Top: y>ymax, Bottom: y<ymin, Right: x>xmax, Left: x<xmin |
| Trivial accept / reject | Both codes 0000 = accept; AND of codes ≠ 0000 = reject |
| Sutherland-Hodgman 4 cases | In→In: keep P; Out→In: add intersection + P; In→Out: add intersection only; Out→Out: add nothing |
Last-Minute Revision Sheet
Random scan → draws lines only, display file
Raster scan → draws all pixels, frame buffer
DDA → floating-point line, simple but slow
Bresenham line → integer decision parameter, p0=2dy-dx
Midpoint circle → 1 octant computed, mirrored ×8, p0=1.25-r
Midpoint ellipse → 2 regions by slope, mirrored ×4
Rectangle fill → fixed xmin/xmax double loop
Ellipse fill → fill between -x/+x at each boundary y
Cohen-Sutherland → 4-bit outcode TBRL, AND test for reject
Circle/ellipse clip → bounding box test, then curve-edge intersection
Sutherland-Hodgman → clip one edge at a time, 4 inside/outside cases