Computer Graphics | Semester 6 Complete Core Notes
Semester 6 - Page 3: Computer Graphics. 25 numbered topics, highlighted rules, worked pixel/transform/curve examples, answered exam questions, diagrams, comparison tables and three complete Python demos. General common-core guide, not an official syllabus or GUI renderer.
Topic map
- Graphics, raster and vector representation
- Pipeline and coordinate spaces
- Pixels, frame buffers and storage
- Color, alpha and blending
- DDA raster line and rounding
- Bresenham line and integer error
- Midpoint circle and symmetry
- Polygon filling and scan conversion
- Translation, scaling and homogeneous matrices
- Rotation, pivot, reflection and shear
- 3D transforms and normals
- Camera and viewing
- Orthographic and perspective projection
- Clipping and viewport mapping
- Line and polygon clipping methods
- Meshes, interpolation and curves
- Bezier curves and B-spline concepts
- Visibility and depth precision
- Lighting and material response
- Flat, Gouraud and Phong shading
- Textures, UVs, filtering and mipmaps
- Aliasing and anti-aliasing
- Animation, double buffering and performance
- Rasterization, ray tracing and realism
- Exam and practical verification
1. Graphics, raster and vector representation
Graphics turns geometric and appearance data into images. Raster stores sampled pixels; vector representation stores shape descriptions that can be rasterized.
Answer: No. Rendering/sampling and display choices affect the final grid.
2. Pipeline and coordinate spaces
A typical pipeline transforms geometry, assembles primitives, clips, rasterizes, shades and applies visibility/blending rules. Exact hardware/API stages vary.
Answer: No. Clipping, occlusion, coverage and rendering rules remain.
Model -> world -> view -> clip -> clipping -> perspective divide -> viewport -> raster samples -> shading/depth/blending
3. Pixels, frame buffers and storage
A pixel is a sample; resolution is dimensions, not physical size. Raw storage depends on channels, bit depth, padding and format; compressed file size is different.
Answer: No. Compression and metadata alter stored size.
4. Color, alpha and blending
RGB channels describe color under a stated color space. Alpha commonly describes opacity/coverage; straight and premultiplied alpha require matching blend conventions.
Answer: No. Color encoding/gamma affects physically meaningful blending.
5. DDA raster line and rounding
DDA samples incremental coordinates along a line. Rounding and endpoint policy determine exact pixel choices; floating-point steps can introduce rounding effects.
Answer: No. State and use a consistent tie convention.
6. Bresenham line and integer error
Bresenham chooses grid steps using an integer error accumulator. General implementations handle octants, signs and endpoint reversal with explicit tie rules.
Answer: No. Test vertical, negative, steep, zero-length and boundary/tie behavior.
Integer raster walk and bounded adjacency checks
def line(x0, y0, x1, y1):
points = []
dx, dy = abs(x1-x0), -abs(y1-y0)
sx, sy = (1 if x0 < x1 else -1), (1 if y0 < y1 else -1)
error = dx + dy
while True:
points.append((x0,y0))
if (x0,y0) == (x1,y1): return points
twice = 2*error
if twice >= dy: error += dy; x0 += sx
if twice <= dx: error += dx; y0 += sy
print("line:", line(0,0,4,2))
checked = 0
for x in range(-6,7):
for y in range(-6,7):
points = line(0,0,x,y)
assert points[0] == (0,0) and points[-1] == (x,y)
assert len(points) == max(abs(x),abs(y))+1
assert all(max(abs(a-c),abs(b-d)) == 1 for (a,b),(c,d) in zip(points,points[1:]))
checked += 1
print("destinations checked:", checked)
print("Checks endpoints/length/adjacency, not every geometric error bound.")
Checked output:
line: [(0, 0), (1, 1), (2, 1), (3, 2), (4, 2)] destinations checked: 169 Checks endpoints/length/adjacency, not every geometric error bound.
7. Midpoint circle and symmetry
Midpoint methods exploit circle symmetry to choose nearby pixels using a decision parameter. Mirror arc points across axes/diagonals and deduplicate symmetry coincidences.
Answer: Special axis/diagonal points coincide under symmetry.
8. Polygon filling and scan conversion
Polygon fill rules decide interior coverage; scanline methods intersect edges and fill spans. Vertex handling and edge inclusion must be consistent.
Answer: Not safely. Inconsistent rules can create seams or double processing.
9. Translation, scaling and homogeneous matrices
Homogeneous coordinates let translation share matrix composition with affine transforms. State row/column-vector convention; transform order is not commutative.
Answer: Generally no. Composition order changes geometry.
10. Rotation, pivot, reflection and shear
Rotation about origin uses sine/cosine; pivot rotation translates to origin, rotates, then translates back. Reflection and shear have different matrices/effects.
Answer: No. Coordinate conventions change the displayed angle direction.
Point (2,1) R90 -> (-1,2) T(3,4) -> (2,6) Reverse: (2,1) -> (5,5) -> (-5,5)
Exact 90-degree transform order and Bezier midpoint
def rotate90(point): return (-point[1], point[0])
def translate(point, shift): return (point[0]+shift[0], point[1]+shift[1])
point, shift = (2,1), (3,4)
print("rotate then translate:", translate(rotate90(point),shift))
print("translate then rotate:", rotate90(translate(point,shift)))
p0,p1,p2 = (0,0),(2,2),(4,0)
t = 0.5
midpoint = tuple((1-t)**2*a+2*(1-t)*t*b+t*t*c for a,b,c in zip(p0,p1,p2))
print("Bezier midpoint:", midpoint)
print("raw RGB bytes:", 800*600*3)
print("raw RGBA bytes:", 800*600*4)
Checked output:
rotate then translate: (2, 6) translate then rotate: (-5, 5) Bezier midpoint: (2.0, 1.0) raw RGB bytes: 1440000 raw RGBA bytes: 1920000
11. 3D transforms and normals
Model/view transforms position geometry; normals require appropriate transformation, especially under nonuniform scale. Normalize directions used by lighting models.
Answer: No. Normal direction constraints and homogeneous translation handling differ.
12. Camera and viewing
A view transform expresses the scene relative to camera position/orientation. Camera movement and object movement must follow the chosen coordinate conventions.
Answer: No. Viewing positions/orients the scene; projection maps the view volume.
13. Orthographic and perspective projection
Orthographic projection lacks depth-based scale change; perspective divides by a homogeneous depth-related coordinate under its convention. API depth/sign ranges differ.
Answer: No. Clipping and valid-view conventions must handle them.
Simple positive-z camera x_screen = f*x/z y_screen = f*y/z (4,2,8), f=2 -> (1,0.5)
14. Clipping and viewport mapping
Clipping trims/rejects primitives outside a chosen region; viewport mapping turns normalized coordinates into screen locations. Clipping differs from occlusion.
Answer: No. Intersections/primitive geometry must be handled.
15. Line and polygon clipping methods
Cohen-Sutherland uses region codes; Liang-Barsky constrains a parametric interval; polygon clipping handles successive boundaries under assumptions..
Answer: No. Geometry and algorithm assumptions need explicit treatment.
Liang-Barsky clipping with degenerate-segment handling
def clip(a, b, bounds):
xmin,ymin,xmax,ymax = bounds
if xmin > xmax or ymin > ymax: raise ValueError("invalid bounds")
dx,dy = b[0]-a[0], b[1]-a[1]
low,high = 0.0,1.0
for p,q in [(-dx,a[0]-xmin),(dx,xmax-a[0]),(-dy,a[1]-ymin),(dy,ymax-a[1])]:
if p == 0:
if q < 0: return None
continue
ratio = q/p
if p < 0: low = max(low,ratio)
else: high = min(high,ratio)
if low > high: return None
return ((a[0]+low*dx,a[1]+low*dy),(a[0]+high*dx,a[1]+high*dy))
for a,b in [((-2,2),(6,2)),((-2,5),(6,5)),((2,2),(2,2))]:
print(a,b,"->",clip(a,b,(0,0,4,4)))
Checked output:
(-2, 2) (6, 2) -> ((0.0, 2.0), (4.0, 2.0)) (-2, 5) (6, 5) -> None (2, 2) (2, 2) -> ((2.0, 2.0), (2.0, 2.0))
16. Meshes, interpolation and curves
Meshes use vertices/edges/faces, often triangles. Curves use control data and basis functions; interpolation/approximation are different promises.
Answer: No. It can shape the curve without being interpolated.
17. Bezier curves and B-spline concepts
Quadratic Bezier uses(1-t)^2 P 0+2(1-t)t P 1+t^2 P 2. B-spline bases offer different local support/continuity under knot choices.
Answer: For a single Bezier segment it influences the whole segment's shape.
18. Visibility and depth precision
A depth buffer compares per-fragment depths under configured conventions. Precision, coplanar geometry and near/far setup can cause z-fighting; not every renderer uses a less-is-near test.
Answer: No. Alpha/blending order needs additional treatment.
19. Lighting and material response
Simple ambient/diffuse/specular terms are teaching approximations. Lambert diffuse uses max(0, N dot L) for normalized directions; materials and light units/conventions matter.
Answer: No. Their magnitudes distort the intended angular term.
20. Flat, Gouraud and Phong shading
Flat uses a face-level result; Gouraud interpolates vertex colors; Phong interpolates normals and evaluates lighting per fragment. Phong shading and the Phong reflectance model are distinct.
Answer: No. It refers to particular interpolation/lighting ideas, not full physical fidelity.
21. Textures, UVs, filtering and mipmaps
Textures map samples through coordinates; minification/magnification filtering handle different sampling scales. Mipmaps trade memory/preprocessing for reduced high-frequency aliasing.
Answer: No. Sampling/filtering still matters.
22. Aliasing and anti-aliasing
Aliasing occurs when sampling cannot represent high-frequency detail. Supersampling and multisampling address selected errors with extra work; they do not solve every shading/texture artifact equally.
Answer: No. Its benefits and sampling behavior are specific to the pipeline.
23. Animation, double buffering and performance
Animation updates state over time; use suitable elapsed-time integration and presentation synchronization. Double buffering separates drawing from displayed buffer under the system's rules.
Answer: No. Frame-time variation, latency and display synchronization matter.
24. Rasterization, ray tracing and realism
Rasterization projects primitives into samples; ray tracing follows ray-scene intersections with chosen light transport approximations. Both have accuracy/performance tradeoffs.
Answer: No. Sampling, models, geometry and numerical issues remain.
25. Exam and practical verification
State coordinate axes, vector/matrix order, rounding/tie rule, color/depth conventions and input assumptions. Test arithmetic and inspect actual rendered pixels for visual work.
Answer: A trace, exact convention, example pixels, checks and limitations.
Projection and visibility
| Concept | Meaning | Common error |
|---|---|---|
| Orthographic | No depth-size scaling | Calling it perspective |
| Perspective | Depth-related homogeneous divide | Ignoring zero/behind-camera handling |
| Clipping | Trim outside region | Confusing with hidden surfaces |
| Depth test | Resolve sampled visibility | Assuming all APIs use same comparison |
| Viewport | Map coordinates to pixels | Ignoring axis/sign convention |
Worked arithmetic
| Question | Calculation | Result |
|---|---|---|
| 800x600 RGB | 800*600*3 | 1440000 raw bytes |
| 800x600 RGBA | 800*600*4 | 1920000 raw bytes |
| Quadratic Bezier at0.5 | .25P0+.5P1+.25P2 | (2,1) for stated controls |
| Lambert example | .8*.5 | 0.4 before other terms |
| Perspective example | 2*4/8, 2*2/8 | (1,0.5) |
Shading and sampling
| Method | Idea | Limit |
|---|---|---|
| Flat | Face-level result | Faceted appearance |
| Gouraud | Interpolate vertex colors | May miss narrow between-vertex highlight |
| Phong shading | Interpolate normals; fragment lighting | Not automatically physically based |
| Mipmaps/filtering | Match texture sampling scale | Extra storage/work and conventions |
| MSAA | Multiple coverage samples | Not every shading artifact |
Revision and practical checklist
State coordinate axes, vector/matrix convention, composition order, tie handling and color/depth rules. Calculate pixels and clipping endpoints, then inspect actual render pixels for any GUI claim. Numeric console output alone does not verify a visual renderer.
Resources and sources
Graphics tutorials support the pipeline, transforms, textures, lighting and depth rules. All diagrams and Python coordinate examples here are original.
Comments
Post a Comment