6.5 Two-Dimensional Transformation

Two-dimensional (2D) transformations are fundamental operations used to manipulate and modify graphical objects in a 2D coordinate system. These transformations are applied to shapes, images, or objects to change their position, orientation, size, or other properties. They form the basis for rendering graphics in computer systems and are commonly used in applications such as gaming, CAD, and computer graphics.


1. Two-Dimensional Translation

Translation is the process of moving an object from one location to another within the 2D coordinate plane without changing its shape, size, or orientation. The object is shifted by a specified distance along the X and Y axes.

  • Mathematical Representation:

    • If ( (x, y) ) is the original point, and ( (tx, ty) ) is the translation vector, then the new point ( (x', y') ) after translation is given by:

    x=x+txx' = x + tx
    y=y+tyy' = y + ty
  • Transformation Matrix:

    T=[10tx01ty001]T = \begin{bmatrix} 1 & 0 & tx \\ 0 & 1 & ty \\ 0 & 0 & 1 \end{bmatrix}

2. Two-Dimensional Rotation

Rotation involves turning an object around a fixed point (typically the origin of the coordinate system) by a specified angle. Positive angles correspond to counterclockwise rotation, and negative angles correspond to clockwise rotation.

  • Mathematical Representation: If the point ( (x, y) ) is rotated by an angle ( \theta ), the new point ( (x', y') ) is given by:

    x=xcosθysinθx' = x \cos \theta - y \sin \theta
    y=xsinθ+ycosθy' = x \sin \theta + y \cos \theta
  • Transformation Matrix:

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

3. Two-Dimensional Scaling

Scaling alters the size of an object by a scale factor along the X and Y axes. Scaling can be uniform (the same factor for both axes) or non-uniform (different factors for X and Y axes).

  • Mathematical Representation: If ( (x, y) ) is the original point and ( sx ) and ( sy ) are the scaling factors along the X and Y axes, then the new point ( (x', y') ) is given by:

    x=xsxx' = x \cdot sx
    y=ysyy' = y \cdot sy
  • Transformation Matrix:

    S=[sx000sy0001]S = \begin{bmatrix} sx & 0 & 0 \\ 0 & sy & 0 \\ 0 & 0 & 1 \end{bmatrix}

4. Two-Dimensional Reflection

Reflection involves flipping an object over a line (axis) such as the X-axis, Y-axis, or a diagonal line, producing a mirror image.

  • Reflection over the X-axis:

    x=xx' = x
    y=yy' = -y
    • Transformation matrix:

    Rx=[100010001]R_x = \begin{bmatrix} 1 & 0 & 0 \\ 0 & -1 & 0 \\ 0 & 0 & 1 \end{bmatrix}
  • Reflection over the Y-axis:

    x=xx' = -x
    y=yy' = y
    • Transformation matrix:

    Ry=[100010001]R_y = \begin{bmatrix} -1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}
  • Reflection over the line ( y = x ):

    x=yx' = y
    y=xy' = x
    • Transformation matrix:

    Rxy=[010100001]R_{xy} = \begin{bmatrix} 0 & 1 & 0 \\ 1 & 0 & 0 \\ 0 & 0 & 1 \end{bmatrix}

5. Two-Dimensional Shear Transformation

Shear transformation distorts an object by shifting its points in one direction (horizontal or vertical) based on its position. It is often used in graphics for creating effects like slanting or skewing.

  • Mathematical Representation:

    • Horizontal shear (shifting X coordinates):

    x=x+shxyx' = x + sh_x \cdot y
    y=yy' = y
    • Vertical shear (shifting Y coordinates):

    x=xx' = x
    y=y+shyxy' = y + sh_y \cdot x
  • Transformation Matrix:

    • Horizontal shear:

    Hshx=[1shx0010001]H_{sh_x} = \begin{bmatrix} 1 & sh_x & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}
    • Vertical shear:

    Hshy=[100shy10001]H_{sh_y} = \begin{bmatrix} 1 & 0 & 0 \\ sh_y & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}

6. Two-Dimensional Composite Transformation

A composite transformation involves applying multiple transformations to an object sequentially. This can include any combination of translation, rotation, scaling, and reflection.

The composite transformation matrix is the product of individual transformation matrices. For example, applying scaling, then rotation, and finally translation can be represented by the following:

Tcomposite=TRST_{composite} = T \cdot R \cdot S

This allows complex transformations to be represented as a single operation, simplifying computation and rendering.


7. 2D Viewing Pipeline

The 2D viewing pipeline is a process that converts a 3D scene or world coordinates into 2D screen coordinates, which can then be displayed on the screen. The pipeline typically involves:

  1. World-to-View Transformation: Converts the world coordinate system to the camera or view coordinate system.

  2. Projection Transformation: Projects the 3D scene onto a 2D plane.

  3. Clipping: Removes objects or parts of objects that fall outside the viewing area.

  4. Window-to-Viewport Transformation: Maps the 2D coordinates to screen coordinates.


8. Clipping

Clipping is the process of removing parts of an object that lie outside a specified region, often referred to as the clipping window. This is critical in computer graphics to ensure that only the visible portion of objects is rendered.

  1. Cohen-Sutherland Line Clipping Algorithm

The Cohen-Sutherland algorithm is used for line clipping. It divides the space into regions and assigns each endpoint a 4-bit code (outcode). Depending on the outcodes of the endpoints, the line can be:

  • Completely inside the clipping window.

  • Completely outside the clipping window.

  • Partially inside the clipping window (requiring further clipping).

  1. Liang-Barsky Line Clipping Algorithm

The Liang-Barsky algorithm is another line clipping algorithm that is more efficient than Cohen-Sutherland for axis-aligned rectangles. It works by testing the parameterized equation of the line against the clipping boundaries.


Conclusion

In 2D graphics, transformations are used to manipulate objects by changing their position, orientation, and size. The core transformations include translation, rotation, scaling, reflection, and shear. These transformations can be combined in a composite transformation to produce more complex effects. The 2D viewing pipeline allows 3D scenes to be converted into 2D representations for display on a screen. Clipping algorithms, such as Cohen-Sutherland and Liang-Barsky, are used to remove parts of objects that fall outside the defined view area.

Last updated