Transformations & Windowing and Clipping



Basic Transformations

Transformations are operations that change the position, size, or orientation of objects.

Types of Basic Transformations:

1. Translation (Shifting)

  • Moves object from one position to another
x=x+tx,y=y+tyx' = x + t_x,\quad y' = y + t_

Example: Move a shape 5 units right, 3 units up

2. Scaling (Resizing)

  • Changes size of object
x=xSx,y=ySyx' = x \cdot S_x,\quad y' = y \cdot S

👉 S>1S > 1: enlarge, S<1S < 1: shrink

3. Rotation (Turning)

  • Rotates object around origin
x=xcosθysinθx' = x\cos\theta - y\sin\thetay=xsinθ+ycosθy' = x\sin\theta + y\cos\thet

👉 Angle measured anticlockwise

Matrix Representation & Homogeneous Coordinates

Why Matrix?

  • Makes transformations easy and consistent
  • Allows combining multiple transformations

Matrix Forms

Translation

[xy1]=[10tx01ty001][xy1]\begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix} = \begin{bmatrix} 1 & 0 & t_x \\ 0 & 1 & t_y \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix}

Scaling

[Sx000Sy0001]\begin{bmatrix} S_x & 0 & 0 \\ 0 & S_y & 0 \\ 0 & 0 & 1 \end{bmatrix}

Rotation 

[cosθsinθ0sinθcosθ0001]\begin{bmatrix} \cos\theta & -\sin\theta & 0 \\ \sin\theta & \cos\theta & 0 \\ 0 & 0 & 1 \end{bmatrix}

Homogeneous Coordinates:

  • Add extra coordinate (w = 1)
  • Represent point as (x, y, 1)

Benefits

  • Enables translation using matrix multiplication
  • Simplifies combining transformations

Composite Transformations

Combining multiple transformations into a single transformation matrix.

Key Concept

Order matters!

👉 Example:

  • Rotate → Translate ≠ Translate → Rotate

Process

  1. Multiply transformation matrices
  2. Apply final matrix to object

Advantages:

  • Faster computation
  • Efficient rendering

Reflection

Creates a mirror image of an object.

Types

1. Reflection about X-axis:

(x,y)(x,y)(x, y) \rightarrow (x, -y

2. Reflection about Y-axis: 

(x,y)(x,y)(x, y) \rightarrow (-x, y

3. Reflection about Origin: 

(x,y)(x,y)(x, y) \rightarrow (-x, -y

4. Reflection about line y=xy = x

(x,y)(y,x)(x, y) \rightarrow (y, x

Shearing

Shearing distorts the shape of an object by shifting one coordinate.

Types:

1. X-Shear:

x=x+Shxyx' = x + Sh_x \cdot 

👉 Object shifts horizontally

2. Y-Shear: 

y=y+Shyxy' = y + Sh_y \cdot x

👉 Object shifts vertically

Effect

  • Rectangle → Parallelogram

Final Summary Table

TransformationPurposeKey Effect
TranslationMove objectPosition change
ScalingResizeSize change
RotationTurn objectOrientation change
ReflectionMirror imageFlip
ShearingDistort shapeSkew

Concept Flow

Basic Transformations → Matrix Form → Homogeneous Coordinates → Composite Transformations → Advanced (Reflection & Shearing)

Viewing Pipeline

The viewing pipeline is the sequence of steps that converts objects from world coordinates to screen coordinates.

Stages:

  1. Modeling Transformation
    • Object → world coordinates
  2. Viewing Transformation
    • Select portion of scene (camera view)
  3. Clipping
    • Remove unwanted parts
  4. Normalization
    • Map to standard coordinate system
  5. Viewport Transformation
    • Map to screen/display

Purpose:

  • Display only the visible portion
  • Improve efficiency

Viewing Transformations

Transformations used to map world coordinates to viewing coordinates.

Key Concepts:

1. Window

  • Area of world we want to see

2. Viewport

  • Area on screen where it is displayed

Window → Viewport Mapping: 

xv=xvmin+(xxwmin)(xvmaxxvmin)xwmaxxwminx_v = x_{vmin} + \frac{(x - x_{wmin})(x_{vmax}-x_{vmin})}{x_{wmax}-x_{wmin}

(Similarly for y)

Importance

  • Controls zooming and panning
  • Maintains aspect ratio

2D Clipping Algorithms

Clipping removes parts of objects that lie outside the viewing window.

Line Clipping Algorithms

A. Cohen-Sutherland Line Clipping

Idea

  • Divide space into 9 regions
  • Assign 4-bit region codes

Steps

  1. Assign region codes to endpoints
  2. If both inside → accept
  3. If both outside (same region) → reject
  4. Else → find intersection

Advantages

  • Simple
  • Efficient for trivial cases

Disadvantages

  • More calculations for complex cases

B. Liang-Barsky Algorithm

Idea

  • Uses parametric line equations
  • Avoids repeated intersection calculations

Equation: 

x=x1+t(x2x1)x = x_1 + t(x_2 - x_1)y=y1+t(y2y1)y = y_1 + t(y_2 - y_1

Advantages

  • Faster than Cohen-Sutherland
  • More efficient

Disadvantages:

  • Slightly complex

C. Line Clipping Against Non-Rectangular Windows

Idea

  • Clip lines against arbitrary shapes (polygon, circle)

Methods:

  • Intersection with each boundary
  • Use polygon clipping techniques

Polygon Clipping

A. Sutherland-Hodgman Polygon Clipping

Idea

  • Clip polygon edge by edge against window

Steps:

  1. Take one boundary
  2. Process all edges
  3. Generate new polygon
  4. Repeat for all boundaries

Advantages:

  • Simple
  • Works well for convex polygons

Disadvantages

  • Not suitable for concave polygons

B. Weiler-Atherton Polygon Clipping

Idea:

  • Handles complex and concave polygons

Key Concept

  • Uses entry and exit points
  • Traverses polygon and window alternately

Advantages

  • Works for all polygon types

Disadvantages

  • Complex implementation

Curve Clipping

Clipping curves (circle, ellipse, spline) against a window.

Methods

  • Approximate curve with line segments
  • Clip each segment
  • Or use mathematical boundary checks

Challenge

  • More complex than line clipping

Text Clipping


Clipping text based on its position relative to window.

Types

1. All-or-None String Clipping

  • Entire text shown or removed

2. All-or-None Character Clipping

  • Individual characters shown/hidden

3. Component Clipping

  • Clip individual character shapes

Final Summary Table

TopicKey IdeaBest For
Cohen-SutherlandRegion codesSimple cases
Liang-BarskyParametricEfficient
Sutherland-HodgmanEdge clippingConvex polygons
Weiler-AthertonEntry/exitComplex polygons
Curve ClippingSegment approximationCurves
Text ClippingCharacter/string levelText rendering

Concept Flow

Viewing Pipeline → Window & Viewport → Clipping → Line → Polygon → Curve → Text