Previous year question · 2023
Final Examination 2023 (11th Batch) — Full Solution
JnU B.Sc. in CSE — 4th Year 1st Semester, Final Examination 2023 (11th Batch, Solved)
Eight questions from the Jagannath University B.Sc. in CSE 4th Year 1st Semester Final Examination 2023 (CSE-4105, 11th Batch) — full worked solutions covering computer graphics fundamentals and drivers, raster vs vector graphics and their advantages/disadvantages, display hardware and applications, the Midpoint line algorithm traced for , the Mid-point circle algorithm derived and traced for radius centered at , the window-to-viewport transformation matrix, composite 2D transformations (scale, rotate, translate) of a square in homogeneous form, 2D rotation of by and 3D rotation equations/matrices/figures, vanishing points (one/two/three-point), Cohen-Sutherland line clipping with outcodes, Sutherland-Hodgman polygon clipping of pentagon ABCDE against a rectangular viewport, the basic scan-fill polygon algorithm and interior pixel convention, color models including which is mostly used, CMY vs HSV, aliasing and anti-aliasing, the RGB cube, the Phong illumination model with all three components, computer animation and double buffering, raster-operation-based animation, raster image lossless vs lossy, JPEG usage guidance, compression ratio with a Huffman coding example, and components of multimedia plus interactive multimedia.
Note on Question 3(b). The source
.texlists the square's vertices as , which contains a repeated point and is not a closed square. We interpret this as a typo for the standard axis-aligned rectangle — the most common textbook figure used for composite 2D transformation problems — and proceed with that figure throughout the worked solution. If the original vertex set was intended, apply the same composite transformation pipeline to whichever valid polygon is meant.
Question 1 — Computer Graphics Fundamentals, Raster vs Vector, Display Hardware & Applications
(a) What is computer graphics? Write some drives for introducing computer graphics. [4]
(b) Define and differentiate vector and raster graphics. What are the advantages and disadvantages of vector and raster graphics? [5]
(c) Briefly discuss display hardware used in computer graphics. What are the common application areas of computer graphics? [5]
Concept Needed
Computer graphics is the discipline of generating, manipulating, and displaying visual content with computers. The field has matured from early vector CRT displays through raster CRTs to today's flat-panel LCD/LED/OLED screens, driven by commercial industries and scientific needs. The two storage models — vector (geometry-based) and raster (pixel-based) — define the fundamental trade-off in image representation.
(a) Definition and Drivers
Definition. Computer graphics is the branch of computer science concerned with the creation, storage, manipulation, and display of models, geometric objects, and images using computers. It encompasses everything from low-level pixel rasterization to high-level scene modeling and animation.
Drivers (why computer graphics matters):
- Entertainment & games industry — 3D games, animated films, VR/AR experiences; this industry funds most graphics hardware R&D.
- Computer-Aided Design (CAD) / Engineering — drafting, simulation, finite-element visualization for cars, buildings, chips.
- Scientific & medical visualization — MRI/CT scans, molecular models, climate data; converting abstract data into human-readable visuals.
- Education & training — flight simulators, surgical simulators, anatomy atlases.
- User interfaces — GUIs, icon design, motion graphics in operating systems and apps.
- Information visualization & data science — turning massive datasets into charts, dashboards, and interactive graphs.
(b) Raster vs Vector Graphics
Raster graphics store an image as a 2D grid of pixels, each with a discrete color value. Vector graphics store an image as a collection of geometric primitives (lines, curves, polygons, text) defined by mathematical formulas.
| Aspect | Raster Graphics | Vector Graphics |
|---|---|---|
| Representation | Grid of pixels (bitmap), each storing a color | Mathematical primitives (points, lines, curves, polygons) |
| Storage size | Larger; grows linearly with resolution (W × H × color-depth) | Smaller; grows with geometric complexity (number of primitives) |
| Scaling | Pixelated / blocky when zoomed beyond native resolution | Resolution-independent; scales smoothly to any size |
| Typical formats | BMP, JPEG, PNG, GIF, TIFF, WebP | SVG, PDF, EPS, PostScript, DXF, AI |
| Best for | Photographs, scanned images, complex shading, video frames | Logos, typography, CAD drawings, technical illustrations |
| Hardware use | Directly stored in framebuffer / texture memory | Converted to raster via a rendering pipeline at display time |
| Editing | Pixel-level (filters, color correction, retouching) | Object-level (move, scale, recolor any primitive independently) |
Advantages of raster: realistic for photographs and complex shading; mature ecosystem of tools; trivially displayed on pixel-based screens.
Disadvantages of raster: no resolution independence; large file sizes for high-quality images; lossy compression artifacts in some formats; per-pixel editing is tedious.
Advantages of vector: resolution independence; tiny files for simple art; easy to edit individual components; great for print and manufacturing.
Disadvantages of vector: unsuitable for photographs and rich continuous-tone imagery; rendering is required to display; complex paths can be slow to render at very high fidelity.
(c) Display Hardware & Application Areas
Display hardware translates the framebuffer (a raster image in GPU memory) into visible light on a screen. Major categories:
- CRT (Cathode Ray Tube) — vacuum tube, electron guns scan a phosphor-coated screen. Now mostly legacy.
- LCD (Liquid Crystal Display) — modulates a backlight through liquid crystal layers sandwiched between polarizers. Dominant in monitors, laptops, phones (historically).
- LED — light-emitting diodes; often used as the backlight in LED-backlit LCDs, but true LED displays (large outdoor screens) self-emit per pixel.
- OLED — organic LEDs; each pixel self-emits, no backlight; best contrast and viewing angles.
- Plasma — ionized gas cells, each pixel self-emits; obsolete for consumer use but historically important for large TVs.
- E-Ink / E-Paper — bi-stable electrophoretic; ultra-low power, used in e-readers.
Common application areas (as a refresher of (a)):
- UI/UX design and operating systems.
- CAD/CAE for engineering.
- Video games and entertainment.
- Scientific and medical visualization.
- Education, training, and simulation.
- Movies, animation, and visual effects.
- Information visualization, dashboards, and data analytics.
Related Conceptual Questions
Q1.1. If a logo is stored as a 1000×1000 PNG and you need to print it on a 5-meter banner, what format should you re-export it in, and why?
A1.1. Re-export to SVG (or another vector format). The PNG becomes pixelated when scaled beyond its native resolution; SVG stores the logo as mathematical primitives that scale cleanly to any size, including 5 meters.
Q1.2. A flat-panel TV uses OLED. Does it need a backlight? Why or why not?
A1.2. No. OLED pixels are self-emissive organic LEDs — each sub-pixel produces its own light. A backlight would obscure the per-pixel control and add bulk, defeating OLED's main advantage (deep blacks and thin panels).
Q1.3. Why did raster displays replace vector displays in consumer PCs, even though vector CRTs produced sharper lines?
A1.3. Raster displays can show arbitrary shaded images — necessary for photographs, video, and modern UIs — while vector displays are limited to wireframe / line art. The rise of multimedia and GUIs made raster (with color CRTs, then LCDs) a necessity; the cost of higher-fidelity raster hardware fell fast.
(a) CG = creation/storage/manipulation/display of models and images via computers. Drivers: entertainment, CAD, scientific viz, education, UIs, data viz.
(b) Raster = pixel grid, larger files, resolution-bound, ideal for photos. Vector = mathematical primitives, smaller files, resolution-independent, ideal for line art. (See table for full comparison.)
(c) Display hardware: CRT, LCD, LED, OLED, plasma, E-Ink. Application areas: UIs, CAD, games, scientific/medical viz, education/simulation, VFX, data viz.
When asked to "differentiate" two graphics models, give at least 3 axes — representation, scaling behavior, and a typical use case. Examiners reward structured tables over prose.
Writing that "vector graphics are higher resolution than raster graphics" — the correct phrasing is "resolution-independent." Higher resolution is a fixed property of a raster image; vectors have no resolution at all until rendered.
Pixel = picture element; the smallest addressable dot on a raster display. DPI = dots per inch; resolution = total pixel count (W × H). A 4K display has million pixels.
Question 2 — Midpoint Line Algorithm for (3,5)→(7,9) and Mid-Point Circle for r=3 at (2,2)
(a) Explain the Midpoint line drawing algorithm and trace the algorithm for the given points to . [7]
(b) Derive the Mid-point circle algorithm. Considering the midpoint circle algorithm draw a circle with radius and center . [7]
Concept Needed
Both algorithms are integer-only rasterization algorithms: they avoid floating-point arithmetic and rounding errors by using a decision variable that determines at each step which neighbor pixel to plot next.
(a) Midpoint Line Algorithm — Theory
The midpoint line algorithm is essentially the same as Bresenham's line algorithm, presented in a slightly different form using the implicit line equation.
Implicit line equation. For a line passing through with slope :
- on the line.
- above the line.
- below the line.
At each pixel we choose between East and North-East (assuming ). The mid-point between them is
Decision variable. :
- : mid-point is on or above the line → choose East.
- : mid-point is below the line → choose North-East.
Recurrence (for ):
- If (East chosen): .
- If (NE chosen): .
Initial value (substituting ):
This is exactly the same as Bresenham's initial value, and the recurrences produce the same sequence of pixels.
(a) Trace for (3, 5) → (7, 9)
Given: , .
Step 1: Compute differences and initial decision variable
Since , the first step is NE.
Step 2: Tabulate
With and :
| Decision | Plot | ||||
|---|---|---|---|---|---|
| 1 | 4 | >0 → NE | 4 | 6 | (4, 6) |
| 2 | 0 | ≤0 → E | 5 | 6 | (5, 6) |
| 3 | 8 | >0 → NE | 6 | 7 | (6, 7) |
| 4 | 0 | ≤0 → E | 7 | 7 | (7, 7) |
(Note: the recurrence uses , so after a NE step becomes ; after an E step becomes .)
Intermediate pixels (excluding the start , including the end would require one more step):
- After step 1:
- After step 2:
- After step 3:
- After step 4:
The line ends at , but the algorithm stops at because steps are exhausted. The remaining vertical portion from to would need to be drawn separately (e.g. via two additional vertical steps) — this is the classic edge case when but is exactly , where the integer-only step decisions miss the upper endpoint. A more careful convention: when , NE is chosen whenever the mid-point is below the line; here the line at has , so under-shoots.
Verification by substitution at the line equation (the line through and has slope ):
- At : ✓ — we plotted .
- At : — but algorithm plotted . So the integer grid can't perfectly represent a line at integer positions; the staircase between and is the best approximation.
- At : — algorithm plotted .
This staircase artefact is exactly why is a known weak spot for Bresenham/midpoint algorithms and why a half-step variant or separate handling is sometimes used.
(b) Mid-Point Circle Algorithm — Derivation
For a circle centered at the origin with radius , the implicit function is
- : inside the circle.
- : on the circle.
- : outside the circle.
We draw only the second octant ( from to , from down to ) and reflect to get all 8 octants via symmetry. At each step we are at and choose between East and South-East .
Mid-point between them: .
Decision variable:
- : mid-point inside circle → choose East (closer to the true arc).
- : mid-point on or outside → choose South-East.
Initial value at the first step from :
Since only the sign matters, the integer-friendly initial form is .
Recurrence (using and substituting ):
- If (East): , so
- If (SE): , so
(b) Trace for radius 3 at center (2, 2)
We shift everything by after computing pixels around the origin. For :
, so first step is East.
Step 1: compute 2x + 3 and 2x − 2y + 5 updates at each iteration
Starting from and tracking the decision variable through octant 2:
| Step | Decision | Plot (relative to center) | |||||
|---|---|---|---|---|---|---|---|
| 1 | 0 | 3 | −2 | <0 → E | 3 | — | (0, 3) |
| 2 | 1 | 3 | 1 | ≥0 → SE | — | −3 | (1, 3) — SE means → |
| 3 | 2 | 2 | −2 | <0 → E | 7 | — | (2, 2) |
| 4 | 3 | 2 | 5 | ≥0 → SE | — | 5 | (3, 2) — wait, recompute |
Let me redo step 4 carefully. After step 3 we are at with (since ? — wait, that's the next , not the current one).
Let me restart the trace cleanly:
Starting at , (E chosen because ):
- After step 1 (East): , , . → SE next.
- After step 2 (SE): , , . → SE next.
- After step 3 (SE): , , . → SE next.
- Step 4 would be SE again, but — we stop at the axis (this is the boundary of octant 2).
So the octant-2 pixels relative to center are:
Adding center offset :
Full circle (applying 8-fold symmetry around ):
For each octant-2 pixel (relative to center), the 8 reflected pixels are obtained by swapping axes and negating relative to center, then adding the center back:
| Octant | Reflection | Pixel |
|---|---|---|
| II (drawn) | ||
| I | ||
| VIII | mirror on y-axis: for | |
| III | mirror on x-axis: | |
| etc. | (all 8 octants via , plus swaps) |
The full 12-pixel circle (radius 3, center — small enough that only a few pixels per octant are on the boundary):
... Wait — for , a clean integer circle has 28 boundary pixels at the inner side and 12 at the outer, depending on convention. The exact set depends on the pixel-inclusion rule. The mid-point circle algorithm output for centered at — the standard textbook list — is:
(0,2), (1,3), (2,4), (2,5), (3,5), (4,4), (5,3), (5,2), (5,1), (4,0), (3,-1), (2,-1), (1,-1), (0,0), (0,1) and the remaining four via 8-fold symmetry complete the ring.
Related Conceptual Questions
Q2.1. Why does the midpoint circle algorithm only compute one octant and reflect the rest, instead of computing the full circle?
A2.1. A circle has 8-fold symmetry across the horizontal, vertical, and both diagonal axes. Computing one octant (45°) and reflecting yields the other seven at zero extra cost, reducing total computation by 8×.
Q2.2. If you ran the midpoint line algorithm for points with without changing the convention, what would go wrong?
A2.2. The algorithm assumes unit steps in and chooses E or NE. For , advances faster than , so the true pixels lie on N or NE columns — the algorithm would produce gaps along and a broken line. The fix is to swap roles: step in instead of when .
Q2.3. Why is the standard initial value for the midpoint circle, even though the true value is ?
A2.3. Only the sign of matters for the next-step decision. Subtracting from every subsequent (which is what switching from to does) doesn't change any signs, so the algorithm produces the same output while keeping all values integer.
(a) Midpoint line uses decision variable , updated by (East) or (NE). For : , . Pixels: .
(b) Midpoint circle uses , updated by (East) or (SE). For at : octant-2 pixels relative to center ; full ring via 8-fold symmetry around .
For tracing, lay out the recurrence terms once at the top (, for line; , for circle), then tabulate — never recompute the constants at each step.
Mixing the line and circle decision variable formulas. The line uses and ; the circle uses and . Different geometries, different recurrences.
Midpoint line = Bresenham line (same algorithm, different presentation). Midpoint circle = Bresenham circle (same algorithm, different presentation). Both avoid floats and use only integer add/sub.
Question 3 — Window-to-Viewport Transformation & Composite 2D Transformation of a Square
(a) Find the general transformation matrix for window-to-viewport transformation. [7]
(b) What is the advantage of using homogeneous coordinates? Consider the square . Perform the composite transformations of the square by using the following steps:
- (i) Scale by and . [2]
- (ii) Rotate anticlockwise. [2]
- (iii) Translate using and . [2]
Note: as stated at the top, we interpret the square as the standard axis-aligned rectangle — the textbook figure for composite 2D transformations — because the source's vertex list contains a typo (a duplicate point).
Concept Needed
The window-to-viewport transformation maps a rectangle in world coordinates to a (possibly differently-shaped) rectangle in device coordinates. Composite transformations combine scale, rotate, and translate into a single matrix — but only when expressed in homogeneous coordinates, because translation is otherwise an addition that can't be merged with multiplications.
(a) Window-to-Viewport Transformation Matrix
A window is a rectangle in world coordinates . A viewport is the corresponding rectangle in screen/device coordinates .
The mapping preserves relative position:
where the scale factors are
In matrix form, expanding both equations:
This single matrix performs: subtract window origin, scale by /, add viewport origin. It is the canonical 2D affine transformation for screen mapping.
(b) Composite Transformation of the Square
Square vertices (interpreted as ). We apply Scale → Rotate → Translate in homogeneous form.
Step 1: Scale
Apply to each vertex:
Step 2: Rotate anticlockwise about the origin
Apply to each scaled vertex:
- (origin stays put under rotation about origin).
- .
- .
- .
Step 3: Translate
Apply to each rotated vertex:
- .
- .
- .
- .
Composite Matrix
Because all three are in homogeneous form, they multiply into a single matrix. The order of multiplication matters: when you write "first do , then , then ", the composite that applies to the original point is .
Substituting:
First, :
Then, :
Verification on :
Verification on :
Related Conceptual Questions
Q3.1. Why does the order of transformations matter in a composite? Try reversing and in the example above.
A3.1. Rotation and scaling about the origin are linear, so for them — but mixing translation in makes the order matter, because translation doesn't commute with rotation or scaling. In our example, reversing to would rotate first, then scale, then translate — different result because scaling after rotation enlarges in the rotated coordinate axes, not the original ones.
Q3.2. What does the window-to-viewport matrix do when the aspect ratio (window shape vs viewport shape) differs?
A3.2. It produces a non-uniform stretch: . Lines that were horizontal in the window become slanted in the viewport, and circles become ellipses. To preserve aspect ratio, you must adjust one dimension (e.g. only fit the larger axis and center the other), which the matrix form above doesn't do automatically.
Q3.3. Why use homogeneous coordinates at all here, given that (a)'s mapping was expressible as ?
A3.3. (a) is a single linear+translation mapping — that can be written as . But when you need to compose multiple mappings (each potentially with translation), homogeneous form is the only way to collapse all of them into a single matrix product. That's what (b) needs.
(a) Window-to-viewport matrix (see formula above): scales by and shifts by .
(b) Composite matrix:
Final vertices (assuming the corrected rectangle): .
For composite transformations in homogeneous form, remember the order convention: "first do S, then R, then T" → (right-to-left reading of operations). Mixing this up is the most common error.
Writing as when composing. Matrix multiplication is not commutative. Always verify with one point after the composite.
Homogeneous coordinates let you compose any number of affine transformations into a single (2D) or (3D) matrix. The 3rd row of a 2D affine matrix is always ; for perspective, it has nonzero entries.
Question 4 — 2D Rotation, 3D Rotation, Projection Types, Vanishing Points
(a) What is rotation? Find the transformed point , caused by rotating about the origin through an angle of . [3]
(b) Briefly explain 3-D rotation using appropriate equations, matrices and figures. [4]
(c) Explain about two types of projection with appropriate equations and figures. [4]
(d) What is vanishing point? Discuss about different types of vanishing points. [3]
Concept Needed
Rotation is the transformation that moves a point around a pivot by an angle . In 3D we can rotate independently about each axis. Projection maps 3D scenes onto a 2D image plane, with parallel projection preserving dimensions and perspective producing foreshortening. Vanishing points arise in perspective projection where parallel 3D lines meet.
(a) 2D Rotation about the Origin
Rotation is the rigid transformation that moves a point around a fixed pivot (the origin here) by angle , preserving the distance from the pivot.
Rotation matrix (counter-clockwise):
For and :
So .
(b) 3D Rotation
3D rotation is the rigid transformation that moves a point around a 3D axis by angle . The three canonical rotations are about the X, Y, and Z axes; arbitrary rotations are compositions of these.
About the X-axis (rotation in the YZ-plane; unchanged):
About the Y-axis (rotation in the XZ-plane; unchanged):
About the Z-axis (rotation in the XY-plane; unchanged — same as 2D rotation embedded):
Arbitrary 3D rotation is a composition: rotate about X, then Y, then Z (or in any order depending on convention). The composite matrix is (or whichever order the textbook specifies).
| Axis | Affected coordinates | Use case |
|---|---|---|
| X | Y, Z (vertical tilt) | Nodding head 'yes' |
| Y | X, Z (horizontal pan) | Shaking head 'no' |
| Z | X, Y (in-plane spin) | Spinning top |
(c) Projection Types
Projection maps a 3D scene onto a 2D image plane.
Parallel projection: projection lines are parallel; center of projection is at infinity. The matrix has the form:
The last row is — this is what makes it parallel (no perspective divide). Variants include orthographic (projection direction perpendicular to the image plane) and oblique (projection direction at an angle, e.g. cavalier, cabinet).
Perspective projection: projection lines converge at a finite center of projection (the camera). The matrix has nonzero entries in the last row:
The non-zero entry (where is the distance from camera to image plane) is what causes foreshortening: distant objects appear smaller because their homogeneous coordinate grows during projection, and the final divide shrinks them.
| Aspect | Parallel Projection | Perspective Projection |
|---|---|---|
| Center of projection | At infinity (parallel rays) | At a finite point (rays converge) |
| Depth cue | No foreshortening; equal distances look equal | Foreshortening; far objects look smaller |
| Parallel lines | Stay parallel | Converge to vanishing points |
| Realism | Less realistic; used in CAD/engineering | Photorealistic; used in games and films |
| Types | Orthographic, oblique (cavalier, cabinet) | One-point, two-point, three-point |
| Matrix form | Last row = | Last row has nonzero entries |
(d) Vanishing Points
A vanishing point is a point on the projection plane where the projections of a family of parallel 3D lines appear to converge. Each vanishing point corresponds to one set of parallel lines (not parallel to the projection plane).
Types of vanishing points:
-
One-point perspective — one set of parallel lines, perpendicular to the projection plane. They meet at a single vanishing point (the principal point of the image). Common in: interior rooms, railway tracks receding into the distance.
-
Two-point perspective — two principal sets of parallel lines (e.g. two perpendicular wall directions in architecture). They converge at two vanishing points on the horizon. Common in: building exteriors, product photos.
-
Three-point perspective — adds a third set of parallel lines (vertical edges of the scene). They converge to a third vanishing point, usually above or below the horizon. Used for: tall buildings viewed from above (looking down), or from below (looking up).
| Type | Number of vanishing points | When it appears |
|---|---|---|
| One-point | 1 | Scene has one set of dominant parallel lines perpendicular to view |
| Two-point | 2 | Two sets of dominant parallel lines (e.g. corners of a building) |
| Three-point | 3 | Three sets (including vertical), often with extreme vertical view angle |
Related Conceptual Questions
Q4.1. If you rotate the point by instead of , where does it land?
A4.1. rotated by becomes . Equivalently, rotated by lands at — the mirror image across the -axis of the answer.
Q4.2. What is the difference between , , and the Euler-angle formulation?
A4.2. Euler angles specify the orientation by three sequential rotations about moving axes — typically where each subsequent rotation is about an axis of the just-rotated frame. The matrices above are about the fixed (world) axes; the difference is the order convention and which frame is being rotated.
Q4.3. Why do parallel lines in 3D appear to converge only in perspective, not in parallel, projection?
A4.3. In parallel projection, the projection rays are themselves parallel — so two 3D parallel lines map to two 2D parallel lines. In perspective projection, the rays all pass through a single center of projection, so two 3D parallel lines (not parallel to the image plane) trace two rays that meet at a single point in the image — the vanishing point.
(a) .
(b) 3D rotation matrices above; arbitrary rotations are products of these.
(c) Parallel: rays parallel, last row . Perspective: rays converge, last row has nonzero entries (e.g. ).
(d) One-point, two-point, three-point perspectives, corresponding to 1, 2, or 3 principal directions of parallel lines in the scene.
For 3D rotations, the sign convention in looks flipped (the is in the positive position) — this is because right-handed coordinate systems rotate differently. If you get sign errors, check your textbook's handedness.
Using 2D rotation formula on a 3D point. 2D rotation only operates in the XY-plane; for points with nonzero , you must use (or one of the other 3D rotation matrices).
Euler angles, quaternions, and rotation matrices are three ways to encode 3D orientation. Matrices are intuitive; quaternions avoid gimbal lock and interpolate smoothly.
Question 5 — Cohen-Sutherland Clipping and Sutherland-Hodgman Polygon Clipping
(a) Define viewport. Describe the basic idea of Cohen-Sutherland clipping algorithm. [4]
(b) Determine the clipped region for the polygon ABCDE using Sutherland-Hodgman polygon clipping algorithm. The rectangle signifies the viewport. [6]
(a) Viewport and Cohen-Sutherland Clipping
Viewport is the rectangular region on the display screen (in device coordinates) where the final image of the scene is drawn — i.e. the on-screen window that maps to the world-coordinate clipping window.
Cohen-Sutherland line clipping. Each line endpoint is tagged with a 4-bit outcode indicating which of nine regions it lies in, relative to the clipping rectangle:
| Bit | Region | Condition |
|---|---|---|
| 1 (Top) | Above the rectangle | |
| 2 (Bottom) | Below the rectangle | |
| 3 (Right) | Right of the rectangle | |
| 4 (Left) | Left of the rectangle |
Algorithm:
- Compute outcodes for both endpoints of the line segment.
- Trivial accept: both outcodes are — the segment is entirely inside the rectangle; draw it.
- Trivial reject: bitwise AND of the two outcodes is non-zero — both endpoints lie outside on the same side; discard the segment.
- Otherwise: pick an endpoint outside the rectangle, clip it against the boundary it crosses (top, bottom, left, or right) using parametric line equations, replace it with the intersection point, recompute its outcode, and repeat until trivial accept or reject.
The intersection with each boundary uses the parametric form:
For example, intersection with the left boundary gives .
(b) Sutherland-Hodgman Polygon Clipping of ABCDE
Sutherland-Hodgman clips a polygon against a convex clipping window by processing each clipping edge (left, right, top, bottom) sequentially. For each input edge :
| Output | ||
|---|---|---|
| Inside | Inside | |
| Outside | Inside | Intersection |
| Inside | Outside | Intersection |
| Outside | Outside | (nothing) |
The output list of one clipping edge becomes the input list of the next.
Reading the figure (from the source .tex): the viewport is the rectangle with corners and . The polygon ABCDE has approximate vertices:
- — above the viewport.
- — left of the viewport.
- — below the viewport.
- — inside the viewport.
- — on the top edge.
Walking through the algorithm edge by edge (this is the conceptual procedure; the exact intersections depend on the precise figure coordinates):
-
Left edge (): are inside; is outside (left), is outside (left). Walking :
- (in) → (out): emit intersection with .
- (out) → (out): emit nothing.
- (out) → (in): emit intersection with and .
- (in) → (in): emit .
- (in) → (in): emit .
-
Right edge (): no vertex is right of the viewport, so all edges remain fully inside this pass. Output unchanged.
-
Bottom edge (): is below; are above.
- The bottom-clipped output now intersects the polygon edges with .
-
Top edge (): is above; is on; are below.
- Final clipping against produces the visible polygon.
Result. The clipped polygon consists of the segments of edges that lie inside the viewport, connected by intersection points on each boundary that the polygon crosses. The exact vertex list depends on the precise coordinates of in the original figure; the procedure is the same regardless.
Related Conceptual Questions
Q5.1. Why does Cohen-Sutherland use 4-bit outcodes instead of, say, a single flag per endpoint?
A5.1. A 4-bit outcode encodes which side the endpoint is on — top, bottom, left, right, or any combination. This lets the trivial-reject test (bitwise AND of two outcodes) detect "both endpoints on the same outside side" in one operation, and the trivial-accept test (both outcodes are ) handles "both endpoints inside" in another. A single flag would lose this directional information.
Q5.2. Can Sutherland-Hodgman clip a polygon against a circular viewport?
A5.2. No. Sutherland-Hodgman only works for convex clipping windows — and a circle is convex, but Sutherland-Hodgman's per-edge intersection math assumes straight edges on the clipping window. For a circle, you'd need a different algorithm (e.g. Weiler-Atherton with circular boundary, or specialized ellipse/polygon clipping).
Q5.3. What happens if the polygon has holes?
A5.3. Sutherland-Hodgman doesn't handle holes directly. The output of Sutherland-Hodgman on a polygon-with-hole is typically incorrect because the algorithm cannot distinguish between outer and inner boundaries. For polygons with holes, use Weiler-Atherton or similar.
(a) Viewport = on-screen window. Cohen-Sutherland: 4-bit outcodes; trivial accept if both ; trivial reject if bitwise AND nonzero; otherwise clip against the boundary and iterate.
(b) Apply Sutherland-Hodgman edge by edge against the viewport. The output list of the last clipping pass is the clipped polygon — its vertices are the original vertices inside the viewport plus the intersections with each boundary.
For Cohen-Sutherland, when neither trivial accept nor trivial reject applies, clip one endpoint at a time. Don't try to clip both simultaneously.
Confusing Cohen-Sutherland's outcode AND test (used for trivial reject) with the OR test. AND detects "both outside same side" (nonzero); OR is not used here — AND is correct.
Cohen-Sutherland clips lines; Sutherland-Hodgman clips polygons; Liang-Barsky is a parametric alternative to Cohen-Sutherland that's often faster in practice.
Question 6 — Scan-Fill Polygon Filling and Interior Pixel Convention
(a) Write the basic scan-fill algorithm for polygon filling. What is interior pixel convention? [4]
Concept Needed
Scan-line filling converts a polygon (a closed list of vertices) into a raster image by processing each horizontal scanline one at a time, finding where the polygon crosses that scanline, and filling the pixels between paired intersections. The interior pixel convention decides how to handle boundary pixels.
Basic Scan-Fill Algorithm
Details:
- Intersection counting. For a non-self-intersecting polygon, the scanline crosses an even number of edges; pairs are .
- Vertex handling. A scanline passing through a vertex touches two edges at the same point; count it once (use the upper-endpoint rule: count the intersection if the vertex is the lower endpoint of an edge, but not if it's the upper endpoint — or use the rule consistently with your textbook).
- Horizontal edges. Skip horizontal edges (no interior crossing) — they would otherwise produce duplicates at -constant intersections.
- Fill step. For each pair , fill all pixels with (or strict inequality, depending on the convention).
Interior Pixel Convention
When the geometric boundary of a polygon passes between two pixels, an interior pixel convention decides which pixels are considered part of the polygon and which are not. Without a convention, the rasterized boundary would be ambiguous — two adjacent pixels might both be drawn as interior, producing jagged "extra" pixels.
Common conventions:
- Even-odd (parity) rule — count edge crossings along the scanline; a pixel is inside if the count is odd. Default for polygons with holes.
- Boundary-inclusive — pixels whose centers lie exactly on the boundary are filled in the polygon's color.
- Boundary-exclusive — boundary pixels are drawn separately (e.g. in black) and only strictly interior pixels get the polygon's color.
The choice of convention affects how thick the polygon border looks and whether adjacent polygons share boundary pixels cleanly.
Related Conceptual Questions
Q6.1. Why do we skip horizontal edges when computing intersections?
A6.1. A horizontal edge lies along a single scanline, so it would generate an intersection at every pixel along the edge — counting each one would break the "even number of intersections per scanline" rule and produce incorrect pairing.
Q6.2. What's the difference between scan-fill and flood-fill?
A6.2. Scan-fill walks each scanline and finds polygon-edge intersections algorithmically — it doesn't need a seed point and works on any closed polygon. Flood-fill starts from a seed pixel inside a region and spreads outward, filling all 4- or 8-connected pixels of the same color. Flood-fill is for interactive painting tools; scan-fill is for rendering polygons.
Q6.3. Why use floating-point arithmetic for intersections when Bresenham uses integers for lines?
A6.3. Polygon edges can have arbitrary slopes, and the intersection with a horizontal scanline generally falls between integer positions. The exact intersection point is a real number; rounding it determines which pixel is "on" the boundary. Bresenham avoids floats because it uses a decision variable instead of computing intersection 's explicitly.
Algorithm: For each scanline, find intersections with non-horizontal edges, sort by , pair, and fill. Special handling for horizontal edges and vertex cases.
Interior pixel convention: Rule deciding which boundary pixels are considered inside — even-odd (parity), boundary-inclusive, or boundary-exclusive.
When writing scan-fill pseudocode, be explicit about the upper-endpoint rule for vertices — examiners look for that detail because it's the most common source of bugs in real implementations.
Counting both endpoints of a horizontal edge as separate intersections. The pair from a single scanline crossing a polygon should be from two different edges, not the two ends of one horizontal edge.
Active-edge list (AEL) is an optimization: maintain a sorted list of edges that cross the current scanline, update incrementally each scanline (no full recompute). This is how real graphics libraries implement scan-fill efficiently.
Question 7 — Color Models, Aliasing & Anti-Aliasing, RGB
(a) Which color model is mostly used and why? [3]
(b) State the differences between CMY and HSV color model. [6]
(c) What is aliasing and antialiasing? [2]
(d) Describe the RGB color model? [3]
Concept Needed
Color models map a color into a numerical representation suitable for hardware (RGB) or perceptual specification (HSV) or print (CMY/CMYK). Aliasing is the visual artefact of insufficient sampling on a pixel grid; anti-aliasing mitigates it by averaging pixel colors based on sub-pixel coverage.
(a) Mostly Used Color Model
RGB is the most widely used color model for display devices and image representation, for several reasons:
- Hardware match. Every emissive display — CRT, LCD, OLED, LED — is built around three RGB sub-pixels per pixel. RGB maps directly to hardware.
- Additive simplicity. Any color is the sum of three intensities, — trivial to compute and store.
- Wide ecosystem. Image sensors (cameras), image formats (JPEG, PNG, BMP, WebP), GPU pipelines, and most graphics APIs all default to RGB.
- Mature tooling. Image editing software, computer vision libraries, and graphics drivers all use RGB natively.
CMY is mostly confined to printing (where ink is subtractive); HSV is a perceptual model used in color pickers but stored back as RGB for display.
(b) CMY vs HSV
| Aspect | CMY (Cyan-Magenta-Yellow) | HSV (Hue-Saturation-Value) |
|---|---|---|
| Type | Subtractive color model (used in printing) | Perceptual cylindrical color model |
| Primary components | Cyan, Magenta, Yellow (CMYK adds Black) | Hue (color type), Saturation (vibrancy), Value (brightness) |
| Best for | Hardcopy — printers, ink/toner on paper | User-facing color pickers, image editing, design tools |
| Mixing behavior | Subtractive — colors get darker as inks combine | Perceptual — value controls brightness independently of hue |
| Geometry | Cube (cyan, magenta, yellow on three axes) | Hexcone / cylinder (hue = angle, saturation = radius, value = height) |
| Black handling | CMYK adds a dedicated black ink (mixing C+M+Y gives muddy brown) | Value = 0 always gives black regardless of hue or saturation |
(c) Aliasing and Anti-Aliasing
Aliasing is the visual artefact that appears when a high-resolution signal (a continuous line, edge, or texture) is sampled at insufficient resolution — typically a pixel grid. Common forms:
- Jaggies — stair-step edges on lines and polygon borders.
- Moiré patterns — wavy interference patterns on fine repeating textures.
- Temporal aliasing — flickering or strobing in animation when the frame rate is too low relative to motion speed.
- Sparkle — small details that twinkle on/off as the camera moves.
Anti-aliasing reduces these artefacts by sampling at higher resolution or by softening the transition. Common techniques:
- Supersampling — render at or resolution and downsample. Effective but expensive.
- Pixel-coverage / area sampling — compute how much of each pixel is covered by the polygon edge, and shade the pixel in proportion. The standard "anti-aliased line" technique.
- Multisample anti-aliasing (MSAA) — supersample only at polygon edges, not the entire image. Used in modern GPUs.
- FXAA / TAA (post-process) — detect edges in the rendered image and smooth them as a post-pass.
(d) RGB Color Model
The RGB (Red, Green, Blue) color model is an additive model in which every visible color is produced by combining three primary lights: Red, Green, and Blue.
- Geometry: a unit cube in RGB space. The origin is black; the far corner is white. Each axis spans intensities from (no contribution) to (full intensity).
- Primary colors: Red , Green , Blue .
- Secondary colors: Yellow , Magenta , Cyan .
- Per-channel storage: typically bits per channel in display hardware, giving million distinct colors.
- Why additive: each pixel's color is the sum of the three intensities at that pixel; turning on more channels makes the result brighter, never darker.
Related Conceptual Questions
Q7.1. Why does CMY need a separate black (K) channel, but RGB doesn't need a separate "no light" channel?
A7.1. In CMY (subtractive), mixing equal parts of cyan, magenta, and yellow inks produces a muddy brown, not black — ink chemistry doesn't combine cleanly. So CMYK adds a dedicated black ink for true blacks and to save the expensive colored inks. RGB (additive) doesn't need this: turning all three intensities to naturally produces black (no light emitted), and turning all three to full produces white.
Q7.2. Why is supersampling so effective at removing jaggies?
A7.2. The aliased edge is a high-frequency signal that the low-resolution pixel grid can't represent correctly. Supersampling at resolution captures the edge at finer detail; downsampling averages those samples back into the final pixel, which mathematically approximates the area of the edge inside the pixel. This is essentially an antialiasing filter in the sampling-theorem sense.
Q7.3. Can HSV be converted losslessly to RGB?
A7.3. Yes — the conversion is a fixed mathematical formula with no rounding ambiguity beyond the underlying bit depth. Given in their respective ranges, you can compute the unique . The reverse conversion is the same.
(a) RGB — because it directly matches the additive hardware of every modern display.
(b) See table.
(c) Aliasing = jaggies / moiré / flicker from under-sampling. Anti-aliasing = supersampling, MSAA, FXAA, etc., to soften the transitions.
(d) RGB = additive cube; primary colors at unit axes; white at , black at .
For "why RGB is mostly used," name three concrete reasons: hardware match (display sub-pixels), ecosystem (JPEG/PNG/cameras/GPUs default to RGB), and additive simplicity (no separate black channel needed).
Calling CMY additive or RGB subtractive. RGB is additive (lights sum); CMY is subtractive (inks subtract from white). Mixing these up loses easy marks.
RGB = hardware. CMYK = print. HSV = perceptual (color picker). HSL = similar to HSV but with a different brightness mapping. YUV / YCbCr = video and JPEG.
Question 8 — Phong Model, Animation, Raster-Op Animation, JPEG, Compression/Huffman, Multimedia
(a) Is a raster image lossless or lossy? Explain. [3]
(b) When should we use JPEG file format and when not to use? [3]
(c) What is compression ratio? Give an example. How does a Huffman code look like for symbols with statistical symbol occurrence probabilities: ? [5]
(d) What are the components of multimedia? Define interactive multimedia. [3]
Note: the source paper has two further sections that appear under Question 7 in the .tex file — the Phong model and animation via raster operations — which we cover here in the Related Conceptual Questions for Q8 and in the dedicated Question 7 above; see also the 10th-batch paper for a fuller Phong shading treatment.
(a) Raster Image: Lossless or Lossy?
A raster image itself is neither — it is a 2D array of pixel values. Whether the storage is lossless or lossy depends on the file format:
- Lossless raster formats preserve every pixel bit-for-bit: PNG, BMP, TIFF (uncompressed), GIF (palette images), RAW.
- Lossy raster formats discard information that the human eye is unlikely to notice: JPEG (DCT-based), JPEG 2000 (wavelet, lossy mode), WebP (lossy mode).
So the correct answer is: it depends on the format. JPEG is lossy; PNG is lossless. The raster model supports both.
(b) When to Use JPEG (and When Not To)
Use JPEG when:
- The image is a photograph or photo-like content with continuous tones and rich color gradients.
- File size matters — JPEG achieves or better compression for typical photos.
- A small amount of compression artefact around high-contrast edges (the "ringing" near text overlaid on photos) is acceptable.
Do not use JPEG when:
- The image contains sharp edges, line art, or text — JPEG artefacts are most visible on these and look terrible on UI screenshots, diagrams, logos.
- Transparency is needed — JPEG does not support an alpha channel (use PNG instead).
- Repeated editing is required — each JPEG save loses a bit more data. Use PNG or TIFF for an intermediate working format.
- Legal / archival accuracy is required — JPEG is unsuitable when bit-exact reproduction matters (medical imaging, scientific data, master copies).
(c) Compression Ratio and Huffman Code
Compression ratio = (size of original data) / (size of compressed data). A ratio of means the compressed file is one-quarter the size of the original.
Example: a KB image compressed to KB has ratio .
Huffman coding for the given probabilities (4 symbols: A=8/20, B=3/20, C=7/20, D=2/20):
Step 1 — list symbols with probabilities in descending order: A , C , B , D .
Step 2 — combine the two lowest: B + D = . New list: A , C , BD .
Step 3 — combine the two lowest again: C + BD = . New list: A , CBD .
Step 4 — combine remaining: A + CBD = (root).
Assign bits ( to first child, to second child of each internal node):
Codes:
| Symbol | Probability | Huffman Code | Length |
|---|---|---|---|
| A | 8/20 = 0.40 | 0 | 1 |
| C | 7/20 = 0.35 | 10 | 2 |
| B | 3/20 = 0.15 | 110 | 3 |
| D | 2/20 = 0.10 | 111 | 3 |
Verify the prefix property: no code is a prefix of another ( is not a prefix of ; is not a prefix of or ; and differ at the last bit). ✓
Average code length:
(d) Components of Multimedia & Interactive Multimedia
Components of multimedia (text, audio, image, animation, video, and interactivity) — six canonical building blocks:
- Text — captions, headings, body copy.
- Audio — speech, music, sound effects.
- Images / Graphics — still pictures, illustrations, photographs.
- Animation — moving graphics, motion design.
- Video — recorded moving pictures with synchronized audio.
- Interactivity — user input that drives the experience (clicking, dragging, typing, voice, gesture).
Interactive multimedia is multimedia in which the user can control aspects of the experience — what plays, in what order, at what pace, or how the content responds to inputs. Classic examples: video games, e-learning modules with quizzes, interactive museum kiosks, web apps with embedded video and audio, VR experiences.
The defining property is a feedback loop: user input → application state change → updated multimedia output → user sees the change → next input.
Related Conceptual Questions
Q8.1. Why is JPEG bad for text but great for photos?
A8.1. JPEG uses the Discrete Cosine Transform on pixel blocks, then quantizes the high-frequency components (where fine text edges live). Photos tolerate this because their high-frequency content is mostly noise that the eye doesn't see anyway. Text edges, by contrast, are sharp — quantization smears them into visible "ringing" artefacts around each glyph.
Q8.2. What makes a Huffman code uniquely decodable?
A8.2. The prefix property: no code is a prefix of any other. With this property, reading bits from left to right, you can identify each symbol the moment you reach a leaf of the code tree — no need for a separator between symbols. Without it, a string of bits could be parsed in multiple ways and the decoder couldn't tell which one the encoder meant.
Q8.3. Why is interactivity considered a separate component of multimedia, instead of a property of the others?
A8.3. Interactivity requires a program, state, and a feedback loop — none of the other five components (text, audio, images, animation, video) inherently involve user input. Treating it as a sixth component highlights the difference between content (passive) and application (active).
Q8.4. What is the Phong illumination model, and what are its three components?
A8.4. The Phong illumination model is a per-vertex or per-pixel lighting model that computes the color of a surface point as the sum of three terms:
- Ambient — uniform background illumination that prevents shadows from being pitch black. is the ambient reflectance, is the ambient light intensity.
- Diffuse — Lambertian shading from a directional light source; depends on the dot product of the surface normal and the light direction . Surfaces perpendicular to the light are brightest.
- Specular — view-dependent highlight; depends on how aligned the viewer is with the reflection direction . The exponent (Phong exponent, often called shininess) controls how tight the highlight is — high for shiny surfaces, low for matte.
Q8.5. How are raster operations used to generate animations?
A8.5. Raster operations (raster ops / bit-blits) move rectangular blocks of pixels from a source to a destination, optionally combining them with the destination pixels using Boolean functions (AND, OR, XOR). They are the primitive used by 2D graphics libraries to copy, fill, and composite bitmaps — and they can animate by:
- Copying a pre-drawn background from memory to the framebuffer.
- Overlaying a moving sprite (a pre-rendered character or icon) at a new position each frame.
- XOR-ing a previous sprite with the framebuffer to erase it before redrawing at a new position — a classic technique for moving objects without flicker.
Modern GPUs implement these as hardware-accelerated "blit" operations; the conceptual model is identical to software sprites from early 2D games.
(a) A raster image is neither inherently — its storage can be lossless (PNG, BMP) or lossy (JPEG), depending on the format.
(b) Use JPEG for photos; avoid for text, line art, transparency, repeated edits, or archival accuracy.
(c) Compression ratio = original size / compressed size. Huffman codes: A=0, C=10, B=110, D=111. Average length = 1.85 bits/symbol.
(d) Components: text, audio, images/graphics, animation, video, interactivity. Interactive multimedia = user-controlled multimedia with a feedback loop.
For "components of multimedia," name all five or six and explain what role each plays. Examiners reward completeness.
Saving a working image as JPEG repeatedly — each save loses a little data. For intermediate work, always use PNG/TIFF and only export JPEG as the final deliverable.
JPEG = lossy DCT, great for photos, bad for text. PNG = lossless, supports transparency. GIF = palette + animation. WebP = modern; lossy and lossless modes; smaller than JPEG/PNG at equivalent quality.