Computer Graphics And AnimationUnit 212 min read
Coordinate Systems & Geometric Transformations
Unit 2 of Computer Graphics And Animation teaches how to represent 2D/3D shapes mathematically, manipulate them with transformations (translation, scaling, rotation, reflection), and map world coordinates to screen coordinates using homogeneous coordinates and window-to-viewport transformations—critical for rendering g
TAKEAWAYS:
- Coordinate systems (Cartesian, homogeneous) define where objects exist in space, with homogeneous coordinates enabling uniform matrix operations.
- Geometric transformations (translation, scaling, rotation, reflection) move, resize, or flip objects using matrices; order matters in composite transformations.
- Window-to-viewport mapping scales and translates world coordinates to screen pixels while preserving aspect ratio, avoiding distortion.
- Homogeneous coordinates (3D for 2D) let all transformations be represented as matrix multiplications, simplifying code and hardware implementation.
- Real-world use: Daraz’s 3D product previews use rotation/scaling; Pathao’s route optimization relies on coordinate transformations to plot paths.
- Exam focus: Derive matrices, prove properties (e.g., scaling order), and solve window-to-viewport mappings—always show step-by-step matrix math.
1. Coordinate Systems in Computer Graphics
1.1 Cartesian vs. Homogeneous Coordinates
- Cartesian coordinates (x, y, z) represent points in space but cannot directly handle translation via matrix multiplication.
- Homogeneous coordinates extend this to (x, y, z, 1) for 2D or (x, y, z, w) for 3D, enabling uniform matrix operations.
Cartesian (2D) → Homogeneous (2D)
(x, y) → (x, y, 1)
Why homogeneous?
- All transformations (translation, scaling, rotation) become matrix multiplications.
- Simplifies pipeline processing (e.g., GPU rendering).
1.2 Common Coordinate Systems
| System | Description | Example Use Case |
|---|---|---|
| World Coordinates | Global space where objects are defined (e.g., 3D scene in a game). | Daraz’s 3D product models. |
| View Coordinates | Camera-centric space after transformations (translation/rotation). | Pathao’s route planning from origin. |
| Screen Coordinates | Pixel space on the display (0,0 at top-left or bottom-left). | UI rendering in eSewa apps. |
2. Geometric Transformations
Transformations modify object positions, shapes, or orientations using matrices. All operations are linear (except reflection) and can be combined via matrix multiplication.
2.1 Translation (Moving Objects)
- Moves an object by (tx, ty, tz) without changing its shape.
- Matrix (2D):
Worked Example: Moving a Point Translate point by : → New point: .
2.2 Scaling (Resizing Objects)
- Scales object along x, y, or z axes by factors (sx, sy, sz).
- Matrix (2D):
Key Property: Two successive scalings are multiplicative: If scaled by then , final scale is .
Worked Example: Scaling a Triangle Scale triangle vertices , , by :
2.3 Rotation (Turning Objects)
- Rotates an object around an axis by an angle .
- 2D Rotation Matrix (about origin):
Worked Example: Rotating a Point Rotate by (clockwise): → New point: .
2.4 Reflection (Mirroring Objects)
- Reflects an object across an axis (x, y, or origin).
- 2D Reflection Matrices:
- X-axis:
- Y-axis:
Worked Example: Reflecting a Point Reflect across the x-axis: → New point: .
2.5 Composite Transformations
- Multiple transformations applied in sequence.
- Order matters: .
Example: Rotation then Translation vs. Translation then Rotation Let , rotate by , then translate by :
- Rotate:
- Translate: → Final: .
Now translate first, then rotate:
- Translate:
- Rotate: → Final: .
Conclusion: Order changes the result!
Mermaid Diagram:
3. Window-to-Viewport Transformation
Maps world coordinates (window) to screen coordinates (viewport) without distortion.
flowchart LR
subgraph Window
A[(-2,-2)]--"Scale by 4"-->B[(2,2)]
C[(2,-2)]--"Translate by (1,1)"-->D[(3,3)]
end
subgraph Viewport
E[(-1,-1)]--"Scale by 200"-->F[(200,200)]
G[(200,-1)]--"Translate by (300,300)"-->H[(500,300)]
end
A-->|"Window→Viewport"|E
D-->F
caption "Window-to-viewport mapping: Scale world coordinates by 4, translate by (1,1), then scale viewport by 200 and translate by (300,300)."Step-by-step window-to-viewport transformation for a 4×4 world mapped to a 500×500 viewport.3.1 Key Concepts
- Window: Defined by to .
- Viewport: Defined by to .
- Aspect Ratio: Must match window/viewport to avoid stretching.
3.2 Transformation Steps
- Scale the window to fit the viewport’s width/height.
- Translate the scaled window to the viewport’s origin.
Formula:
3.3 Worked Example
Window: to . Viewport: to .
Transform point :
- Scale:
- Translate: Already at viewport origin. → Final: .
3.4 Preserving Aspect Ratio
If window/viewport aspect ratios differ, shearing occurs. To avoid:
- Use scaling factors that match the aspect ratio:
- If , choose the smaller scale to fit entirely.
Mermaid Diagram:
4. 3D Transformations
Extend 2D matrices to 3D for depth (z-axis).
4.1 Rotation Matrices (3D)
- X-axis:
- Y-axis:
- Z-axis:
4.2 Worked Example: Rotating a 3D Point
Rotate by about the y-axis: → New point: .
5. Real-World Applications
In the Real World
Daraz 3D Product Previews
- Idea: Rotation and scaling transformations let users view products from any angle.
- How: Daraz’s 3D models are rotated/scaled via matrix math to render dynamic views on mobile/web.
Pathao Route Optimization
- Idea: Coordinate transformations map GPS coordinates (world space) to a 2D map (viewport).
- How: Pathao’s algorithm translates real-world locations to a simplified grid for pathfinding.
Ncell’s 3D Network Visualization
- Idea: Window-to-viewport mapping scales global network diagrams to fit mobile screens.
- How: Ncell’s app renders tower locations (world coordinates) as icons on a 2D map (viewport).
6. Exam Tips
- Matrix Derivation: Always show steps for deriving transformation matrices (e.g., rotation, reflection). Use trigonometric identities for angles.
- Order Matters: For composite transformations, prove why with a concrete example.
- Window-to-Viewport: Memorize the scaling/translation formula. For aspect ratio preservation, always check if .
- Homogeneous Coordinates: Explain why they enable uniform matrix operations (e.g., translation becomes multiplication).
- Worked Examples: Practice transforming points/vertices. Show every matrix multiplication step.
- Real-World Tie: Relate transformations to apps like Daraz or Pathao (e.g., "Daraz uses rotation matrices to render 3D products").
Common Pitfalls:
- Forgetting homogeneous coordinates for translation (use ).
- Mixing up viewport origin (top-left vs. bottom-left).
- Incorrectly applying scaling factors in window-to-viewport (always divide by window size).
Based on the TU BCA syllabus for Computer Graphics And Animation (CACS305), unit 2.
Discussion
Loading…