Unit III: Windowing, Clipping, 3D Transformation, and Projections
1. Windowing
Concept of Window and Viewport
• Window: A rectangular region in the world coordinate system (WCS) that defines what
part of the scene we want to display.
• Viewport: A rectangular region in the device coordinate system (screen) where the
selected window content is displayed.
• Purpose: To map objects from the world coordinate system to the device/screen
coordinate system.
World Coordinates:
(xwmin, ywmax) (xwmax, ywmax)
+------------------------+
| |
| Window |
| |
+------------------------+
(xwmin, ywmin) (xwmax, ywmin)
Screen Coordinates (Viewport):
(xvmin, yvmax) (xvmax, yvmax)
+------------------------+
| |
| Viewport |
| |
+------------------------+
(xvmin, yvmin) (xvmax, yvmin)
Viewing Transformations
The transformation from world coordinates to viewport coordinates involves:
1. Translate the window to the origin.
2. Scale the window to the size of the viewport.
3. The transformation can be expressed as:
xv = xvmin + [(xw - xwmin) * (xvmax - xvmin)] / (xwmax - xwmin)
yv = yvmin + [(yw - ywmin) * (yvmax - yvmin)] / (ywmax - ywmin)
1. Comparison Tables
Window vs Viewport
Feature Window Viewport
Part of world coordinates to Area on the screen where the window is
Definition
display mapped
Coordinate
World Coordinate System (WCS) Device/Screen Coordinate System
System
Units Real-world (e.g., meters, km) Pixels
Purpose Select portion of scene Display selected portion
2. Line Clipping
Cohen-Sutherland Line Clipping Algorithm
• Divides the area into 9 regions using window boundaries.
• Each region is given a 4-bit code (Outcode) indicating the position of the point relative to
the window.
• Steps:
1. Compute Outcodes for both endpoints.
2. If both Outcodes are 0000 → trivially accepted.
3. If (Outcode1 & Outcode2) ≠ 0 → trivially rejected.
4. Else → partially visible, clip the line by finding intersection and re-check.
Cohen-Sutherland Region Codes
1001 1000 1010
+--------+--------+
| | |
| | |
0001 +----+--------+ 0010
| | |
| | |
+--------+--------+
0101 0100 0110
3. Polygon Clipping
Sutherland-Hodgeman Polygon Clipping
• Used for clipping polygons against a rectangular clip window.
• Works edge by edge:
o Clip the polygon against one edge of the clip window.
o The result becomes the input for clipping against the next edge.
• For each edge, apply rules for each polygon edge:
o Both points inside → keep the end point.
o First point outside, second inside → keep intersection and end point.
o First inside, second outside → keep only intersection.
o Both outside → discard.
• Convex polygons: Clipped properly.
• Concave polygons: Might need additional handling (e.g., splitting)
Sutherland-Hodgeman Polygon Clipping
Step-by-step clipping against each edge of the window:
Input Polygon → Clip Left Edge → Clip Right Edge →
Clip Bottom Edge → Clip Top Edge → Final Polygon
Cohen-Sutherland vs Sutherland-Hodgeman
Cohen-Sutherland Line
Feature Sutherland-Hodgeman Polygon Clipping
Clipping
Type Line Clipping Polygon Clipping
Convex & Concave Polygons (needs extra care for
Handles Lines
concave)
Region codes + Bitwise
Technique Edge-by-edge clipping
operations
Output Clipped line segments Clipped polygon
4. 3D Transformation
Basic Transformations
• Translation:
• Scaling:
• Rotation about axes:
o About X-axis:
Y
| *
| * ← Rotating points
| *
+------------------ Z
X
o About Y and Z axes are similar.
• Rotation about arbitrary axis: Involves translating the object, aligning the axis with a
coordinate axis, applying rotation, then reversing.
Before: (x, y, z)
After: (x, y, -z)
Reflections
• About XY-plane:
• About YZ and XZ are similar.
• About an arbitrary plane: More complex, usually involves defining the plane equation
and applying combined transformations.
5. Projections
Types of Projections
Two main types:
• Parallel Projection
Cavalier (full depth)
\ (lines drawn at 45°)
Cabinet (half depth)
\ (lines drawn at 63.4° with 0.5 scale)
• Perspective Projection
Parallel Projection
1. Oblique Projection
• Projectors are not perpendicular to the view plane.
• Two types:
o Cavalier Projection: Full depth (foreshortening factor = 1)
o Cabinet Projection: Half depth (foreshortening factor = 0.5)
2. Orthographic Projection
• Projectors are perpendicular to the projection plane.
• Types:
o Isometric Projection: Equal angles (120°) between axes.
o Dimetric Projection: Two axes have equal angles.
o Trimetric Projection: All axes have different angles.
Orthographic Projection Types
Type Axes Angles Equal Dimensions? Use Case
Isometric 120° between all axes Yes CAD models
Dimetric Two equal, one different No Technical illustrations
Trimetric All different No Complex designs
Perspective Projection
Key Idea: Objects appear smaller as they are further from the viewer.
Types based on Vanishing Points:
• 1-Point Perspective: One vanishing point (e.g., looking down a hallway).
Vanishing Point
_____/|\_____
/ | \
/ | \
Front Depth Lines
• 2-Point Perspective: Two vanishing points (e.g., looking at a corner).
VP1 VP2
\ /
\ /
\ /
\ /
Front Edge
• 3-Point Perspective: Three vanishing points (adds vertical perspective, like looking from
above or below).
VP1 VP2
\ /
\ /
\ /
\ /
\ / ← Front Edge
VP3 (Below or above view)
Parallel vs Perspective Projection
Feature Parallel Projection Perspective Projection
Projector Lines Parallel Converge at vanishing point
Depth Effect Not realistic Realistic (depth perception)
Types Orthographic, Oblique 1-point, 2-point, 3-point
Uses Engineering, CAD Art, Gaming, 3D Rendering