4.1 Clipping Algorithms
Analogy: Taking a photo. Anything outside the viewfinder doesn't get recorded.
1. Cohen-Sutherland Line Clipping
Uses 4-bit Region Codes (TBRL - Top, Bottom, Right, Left) to quickly accept or reject lines.
The Logic:- Center (Visible): 0000
- Corners: e.g., Top-Left = 1001 (Top=1, Left=1).
- Rule 1 (Trivial Accept): If both points are 0000, keep it.
- Rule 2 (Trivial Reject): If (Code1 AND Code2) $\neq$ 0000, throw it away. (Both are outside the same edge).
- Rule 3 (Clip): If neither, calculate intersection and chop.
2. Mid-Point Subdivision Clipping
Concept: A "Binary Search" approach. Instead of calculating complex intersections (slow math), it simply cuts the line in half.
- Is the whole line visible? No.
- Divides into two halves.
- Is the first half visible? Yes -> Keep. No -> Divide again.
- Repeat until pixel size is reached.
3. Sutherland-Hodgman Polygon Clipping
Problem: Clipping a shape is harder than a line because cutting off a corner creates new edges.
The Pipeline Approach:Clip the entire polygon against one boundary at a time.
- Input Polygon $\rightarrow$ Left Clipper $\rightarrow$ Output
- Input $\rightarrow$ Right Clipper $\rightarrow$ Output
- Input $\rightarrow$ Top Clipper $\rightarrow$ Output
- Input $\rightarrow$ Bottom Clipper $\rightarrow$ Final Polygon
Ensure you can solve a Liang-Barsky clipping problem. It is more efficient than Cohen-Sutherland and frequently carries 10+ marks.
mindmap
root((Clipping Logic))
Code Checks
Cohen-Sutherland
TBRL Codes
Accept/Reject
Divide Checks
Mid-Point Subdiv
Binary Search
Good for Hardware
Shape Checks
Sutherland-Hodgman
Pipeline Cutters
L -> R -> T -> B
4.2 Projections
Analogy: Casting a shadow.
- Parallel: Sun is far away. Shadows are same size as object.
- Perspective: Flashlight is close. Shadows get bigger; objects look smaller.
| Feature | Parallel Projection | Perspective Projection |
|---|---|---|
| Visual | Parallel lines stay parallel. No vanishing point. | Parallel lines meet at a "Vanishing Point". |
| Size | True to size (Measurements are accurate). | Distant objects look smaller (Realistic). |
| Use Case | Architects, Engineers, CAD. | Games, Movies, Human Vision. |
Sub-Types
- Parallel Values:
- Orthographic: Top, Front, Side views.
- Oblique: Slanted view (Cavalier, Cabinet).
- Perspective Values: 1-point, 2-point, 3-point.
mindmap
root((View Types))
Parallel
CAD / Architect
True Size
No Vanishing Point
Perspective
Human Eye / Game
Shrink with Dist
Vanishing Points
4.3 The Math (Deep Dive)
Formulas often asked in "Hard" sections.
1. Perspective Formula (Similar Triangles)
Concept: Divide by depth ($z$).
If simple camera at Origin and Screen at distance $d$: $$x' = x \cdot \frac{d}{z}$$ $$y' = y \cdot \frac{d}{z}$$(As $z$ increases, $x'$ gets smaller).
2. Oblique Projection Math
The front face is flat ($z=0$), but sides go back at angle $\phi$.
- $x' = x + L \cdot z \cdot \cos\phi$
- $y' = y + L \cdot z \cdot \sin\phi$
- Cavalier: Angle $45^\circ$, Length $L=1$. (Looks long).
- Cabinet: Angle $63.4^\circ$, Length $L=0.5$. (Looks realistic).
3. Vanishing Points Logic
Tricky Question: What makes it 1, 2, or 3 point perspective?
Answer: It depends on how many axes ($x,y,z$) intersect/cut the Projection Plane.
- 1-Point: Plane cuts 1 axis ($z$). (e.g., Tunnel view).
- 2-Point: Plane cuts 2 axes ($x, z$). (e.g., Street corner).
- 3-Point: Plane cuts 3 axes ($x,y,z$). (e.g., Bird's eye view from skyscraper).
mindmap
root((Projection Math))
Perspective
Divide by Z
x' = x (d/z)
Oblique
Add Offset
x' = x + LzCos
Cavalier vs Cabinet
Vanishing Pts
Axes Intersected
1-Pt (Z only)
2-Pt (X, Z)
3-Pt (X, Y, Z)