Computer GraphicsUnit 67 min read
Projection & Viewing: Types, Transformations, Clipping
Unit 6 of Computer Graphics covers projection techniques (orthographic, oblique, perspective), the 3D viewing pipeline, window-viewport transformations, and clipping algorithms like Cohen-Sutherland, with mathematical derivations and practical examples.
TAKEAWAYS:
- Projection types differ by parallelism (orthographic/oblique) vs. perspective convergence, each with distinct matrices and visual effects.
- Viewing pipeline transforms world coordinates → view volume → normalized device coordinates → screen space via projection and viewport scaling.
- Window-viewport mapping uses linear interpolation to scale/translate 3D regions to 2D screens, requiring region codes for clipping.
- Cohen-Sutherland clips lines against rectangular windows in 4-bit codes (inside/outside flags), rejecting or trimming edges iteratively.
- Oblique projections (cabinet/cavalier) use shear matrices to tilt axes while preserving parallelism, unlike perspective’s vanishing points.
- Exam focus: Derive matrices, trace transformations, and apply clipping algorithms to given coordinates.
1. Projection Fundamentals
Projection maps 3D world coordinates to 2D screen space. Key distinctions:
- Parallel projections: Projectors are parallel (orthographic/oblique). No vanishing points; parallel lines remain parallel.
- Perspective projections: Projectors converge at a viewpoint. Parallel lines meet at a vanishing point.
1.1 Orthographic Projection
- Definition: Projectors are perpendicular to the projection plane (no foreshortening).
- Matrix:
For a view volume defined by
[-w, w] × [-h, h] × [-d, d], the orthographic projection matrix is:P = \begin{bmatrix} \frac{2}{w} & 0 & 0 & 0 \\ 0 & \frac{2}{h} & 0 & 0 \\ 0 & 0 & \frac{-2}{d} & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} - Applications: Technical drawings, CAD (no distortion).
1.2 Oblique Projection
- Definition: Projectors are parallel but angled. Two variants:
- Cavalier: Shear factor = 1 (preserves lengths).
- Cabinet: Shear factor < 1 (foreshortens receding lines).
- Matrix Derivation:
Shear the X-axis by angle θ (tanθ = shear factor):
whereP_{\text{oblique}} = \begin{bmatrix} 1 & 0 & -s & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}s = tanθ. Combine with orthographic projection.
Comparison Table:
| Feature | Orthographic | Oblique (Cavalier) | Perspective |
|---|---|---|---|
| Parallelism | Yes | Yes | No (converges) |
| Vanishing Pt | None | None | Yes |
| Matrix | Diagonal | Shear + Ortho | Perspective divide |
| Use Case | Technical drawings | Isometric views | Realistic rendering |
2. The 3D Viewing Pipeline
Transforms world coordinates to screen pixels via:
- Modeling Transform: Object-specific (translation/rotation/scaling).
- Viewing Transform: Aligns world to camera (eye) coordinates.
- Projection Transform: Maps 3D to 2D (orthographic/perspective).
- Viewport Transform: Scales to screen resolution.
Mermaid Diagram:
flowchart TD
A[World Coordinates] --> B[Modeling Transform]
B --> C[Viewing Transform\n(LookAt Matrix)]
C --> D[Projection\n(Ortho/Perspective)]
D --> E[Normalized Device Coords\nNDC: [-1,1]x[-1,1]]
E --> F[Viewport Transform\nScreen Mapping]
F --> G[Pixel Coordinates]2.1 Viewing Transform (LookAt Matrix)
Defines camera position (ex, ey, ez), target (tx, ty, tz), and up vector (ux, uy, uz).
Steps:
- Translate world so camera is at origin:
T = -[ex, ey, ez]. - Rotate to align camera’s Z-axis with view direction
D = (tx-ex, ty-ey, tz-ez). - Normalize D and compute orthonormal basis (X, Y, Z axes).
LookAt Matrix:
M_{\text{view}} = \begin{bmatrix}
X_x & X_y & X_z & -X \cdot E \\
Y_x & Y_y & Y_z & -Y \cdot E \\
Z_x & Z_y & Z_z & -Z \cdot E \\
0 & 0 & 0 & 1
\end{bmatrix}
where E = [ex, ey, ez].
3. Window-Viewport Transformation
Maps a 3D window (e.g., a rectangular region in world space) to a 2D viewport on screen.
3.1 Definitions
- Window: 3D region defined by min/max
(x_w, y_w, z_w)coordinates. - Viewport: 2D screen region
(x_v, y_v)with width/height(w_v, h_v). - Transformation:
Scale and translate from window to viewport:
x_v = x_w \cdot \frac{w_v}{w_w} + x_{\text{min}} y_v = y_w \cdot \frac{h_v}{h_h} + y_{\text{min}}
3.2 Example: Quadrilateral Mapping
Given:
- Window: Diagonal endpoints
(1,1)and(4,4)→w_w = 3,h_w = 3. - Viewport: Diagonal
(3,2)to(6,6)→w_v = 3,h_v = 4,x_min=3,y_min=2.
Vertices:
| Window (x,y) | Viewport (x_v, y_v) |
|---|---|
| (1,1) | , |
| (1,2) | , |
| (2,2) | , |
| (3,4) | , |
4. Line Clipping: Cohen-Sutherland Algorithm
Clips a line against a rectangular window using region codes (4-bit flags for left/right/top/bottom).
4.1 Region Codes
Each endpoint gets a 4-bit code:
- Bit 0 (L): Left of window (
x < x_{\text{min}}). - Bit 1 (R): Right of window (
x > x_{\text{max}}). - Bit 2 (B): Below window (
y < y_{\text{min}}). - Bit 3 (T): Above window (
y > y_{\text{max}}).
Example:
Window: A(20,20) to D(90,70).
Point P(10,30) → Code 1001 (L=1, T=1).
**4.2 Algorithm Steps
- Compute codes for both endpoints.
- If both codes are
0000, accept the line. - If bitwise AND of codes is non-zero, reject.
- Otherwise, clip the line:
- Find intersection with window edge.
- Update the endpoint and recompute its code.
- Repeat until accept/reject.
Trace for Line (10,30) to (80,40):
P1 = (10,30)→ Code1001(L, T).P2 = (80,40)→ Code0010(T).- AND =
0000→ Proceed. - Clip
P1against top edge (y=70): Intersection:(10 + (70-30)/(40-30)*70, 70) = (10 + 40, 70) = (50,70). - New
P1 = (50,70)→ Code0000→ Accept.
5. Perspective Projection
Simulates human vision with a viewpoint and projection plane.
5.1 Matrix Derivation
For a camera at (0,0,0) looking down Z-axis:
P_{\text{perspective}} = \begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & \frac{n+d}{n-d} & \frac{2nd}{n-d} \\
0 & 0 & -1 & 0
\end{bmatrix}
where n = near plane, d = far plane.
Perspective divide: Divide x,y by w after transformation.
5.2 Vanishing Points
Parallel lines converge at infinity. For example:
- 1-point perspective: Lines parallel to Z-axis converge at a single point.
- 2-point perspective: Two sets of parallel lines converge at two points.
Mermaid Diagram:
mindmap
root((Perspective Projection))
Matrix
4x4 Homogeneous
Perspective Divide
Vanishing Points
1-Point
2-Point
3-Point
Applications
Realistic Rendering
Architecture Visualization6. Exam Tip
Do’s:
- Derive matrices: Show all steps for orthographic/oblique/perspective matrices.
- Trace transformations: For a given point, apply modeling → viewing → projection → viewport.
- Clipping: Use Cohen-Sutherland with region codes; show intersection calculations.
- Diagrams: Draw parallel vs. perspective rays to distinguish projections.
Don’ts:
- Skip normalization in projection matrices.
- Assume window/viewport dimensions without calculating scaling factors.
- Forget to handle perspective divide (divide by
wafter transformation).
Common Pitfalls:
- Confusing cavalier (shear=1) and cabinet (shear<1) oblique projections.
- Misapplying the LookAt matrix (forgetting to normalize axes).
- Clipping errors due to incorrect region code updates.
Based on the TU BSc CSIT syllabus for Computer Graphics (CSC214), unit 6.
Discussion
Loading…