Study Material
Semester-04
CG
Unit-03

Unit 3: Windowing, Clipping, 3D Transformation, and Projections

Introduction to Windowing

Windowing is a crucial concept in computer graphics that allows the display of a particular portion of a scene on the screen. The windowing process involves selecting a portion of the graphical scene, known as the window, and mapping it to the display area, referred to as the viewport.

Concept of Window and Viewport

  • Window: The window is a rectangular region in the world coordinate system that defines the part of the scene to be displayed. It determines which objects are visible on the screen. The coordinates of the window are specified in world coordinates.

  • Viewport: The viewport is a rectangular area on the display device where the window is mapped. It represents the area of the screen that displays the window's contents. The coordinates of the viewport are specified in screen coordinates.

Viewing Transformations

Viewing transformations are processes that convert world coordinates to screen coordinates. The main goal is to map the objects in the window to the corresponding positions in the viewport. This involves several steps:

  1. Normalizing the Window: The coordinates of the window are transformed into normalized device coordinates, which typically range from (0,0) to (1,1).

  2. Mapping to Viewport: The normalized coordinates are then mapped to the viewport coordinates by scaling and translating them based on the dimensions of the viewport.

  3. Clipping: Objects that fall outside the window are clipped to ensure that only the relevant portion of the scene is displayed.


Line Clipping

Line clipping is a technique used to restrict the drawing of lines to a specified area, ensuring that only visible portions of lines are rendered. This is particularly important in computer graphics to optimize rendering performance and avoid unnecessary computations for off-screen objects.

Cohen-Sutherland Method of Line Clipping

The Cohen-Sutherland algorithm is one of the most widely used line clipping algorithms. It uses a divide-and-conquer approach to efficiently determine the visible portion of a line segment within a rectangular clipping window.

Steps of the Cohen-Sutherland Algorithm:

  1. Define Regions: The algorithm divides the 2D plane into nine regions, using a rectangular clipping window. Each region is assigned a 4-bit binary code (outcode) to represent its position relative to the clipping window.

  2. Compute Outcodes: For each endpoint of the line segment, the algorithm computes the outcode based on its position relative to the clipping window.

  3. Trivial Acceptance and Rejection:

    • If both endpoints have an outcode of 0000, the line is entirely inside the window and is accepted.
    • If the logical AND of the outcodes is not zero, the line is entirely outside the window and is rejected.
  4. Line Intersection: If the line segment is partially inside the window, the algorithm calculates the intersection points with the clipping window's edges and updates the endpoints accordingly.

  5. Repeat: The process repeats until the line segment is either accepted or rejected.

Applications of Line Clipping

  • Rendering Optimization: Line clipping reduces the number of computations needed for rendering, especially in complex scenes with many objects.
  • User Interface: Clipping is used in GUI applications to restrict drawing operations within specified bounds, improving performance and visual clarity.

Polygon Clipping

Polygon clipping is the process of removing the parts of polygons that lie outside a defined clipping window. This is essential in computer graphics for efficient rendering and visibility determination.

Sutherland-Hodgman Method for Convex Polygons

The Sutherland-Hodgman algorithm is a commonly used method for clipping convex polygons. This algorithm works by processing each edge of the polygon and determining its intersection with the clipping window.

Steps of the Sutherland-Hodgman Algorithm:

  1. Initialize: Start with the input polygon and the clipping window.

  2. Process Each Edge: For each edge of the polygon:

    • Determine its position relative to the clipping window.
    • Calculate intersection points with the clipping window edges as needed.
    • Add the visible vertices of the polygon to the output list.
  3. Output the Clipped Polygon: Once all edges have been processed, the resulting list represents the clipped polygon.

Sutherland-Hodgman Method for Concave Polygons

The Sutherland-Hodgman algorithm can also handle concave polygons, but it requires additional steps to ensure that all edges are processed correctly. The main difference lies in the management of vertices and the order in which edges are added to the output list.

Steps for Concave Polygons:

  1. Initialize: Begin with the concave polygon and the clipping window.

  2. Iterate Through Edges: For each edge of the concave polygon:

    • Determine whether it is inside or outside the clipping window.
    • Calculate intersections and manage the output vertices to handle concave sections appropriately.
  3. Output the Result: Generate the final output polygon that represents the visible portion of the concave polygon.

Applications of Polygon Clipping

  • Graphics Rendering: Polygon clipping is essential in 2D and 3D graphics rendering to ensure that only visible parts of shapes are displayed, reducing rendering time and resource usage.
  • Game Development: Clipping is widely used in video games to manage visibility and optimize rendering for complex scenes.

3D Transformation

3D transformation techniques are crucial in computer graphics for manipulating three-dimensional objects. These transformations include translation, scaling, rotation, and reflection.

Translation

Translation in 3D involves moving an object from one location to another along the X, Y, and Z axes. The translation operation is defined by a translation vector (tx, ty, tz), which specifies the distance to move the object along each axis.

Formula:

  • New coordinates (x', y', z') after translation can be calculated as:
    • x' = x + tx
    • y' = y + ty
    • z' = z + tz

Scaling

Scaling modifies the size of an object in three-dimensional space. Scaling factors (sx, sy, sz) determine how much the object is enlarged or shrunk along each axis.

Formula:

  • New coordinates (x', y', z') after scaling can be calculated as:
    • x' = x * sx
    • y' = y * sy
    • z' = z * sz

Rotation

Rotation in 3D can occur around the X, Y, or Z axes. Each rotation can be defined by an angle (θ), and the new coordinates after rotation can be computed using trigonometric functions.

  1. Rotation about the X-axis:

    • New coordinates (x', y', z') after rotation:
      • y' = y _ cos(θ) - z _ sin(θ)
      • z' = y _ sin(θ) + z _ cos(θ)
  2. Rotation about the Y-axis:

    • New coordinates (x', y', z') after rotation:
      • x' = z _ sin(θ) + x _ cos(θ)
      • z' = z _ cos(θ) - x _ sin(θ)
  3. Rotation about the Z-axis:

    • New coordinates (x', y', z') after rotation:
      • x' = x _ cos(θ) - y _ sin(θ)
      • y' = x _ sin(θ) + y _ cos(θ)

Reflection

Reflection transforms an object by creating a mirror image across a specified plane (XY, YZ, XZ, or an arbitrary plane).

  1. Reflection about the XY Plane:

    • New coordinates (x', y', z') after reflection:
      • x' = x
      • y' = y
      • z' = -z
  2. Reflection about the YZ Plane:

    • New coordinates (x', y', z') after reflection:
      • x' = -x
      • y' = y
      • z' = z
  3. Reflection about the XZ Plane:

    • New coordinates (x', y', z') after reflection:
      • x' = x
      • y' = -y
      • z' = z

Applications of 3D Transformation

  • Animation: 3D transformations are essential for animating characters and objects in films and video games.
  • Modeling: 3D modeling software uses transformations to create and manipulate complex shapes and structures.

Projections

**

Projections** in computer graphics are techniques used to represent three-dimensional objects on a two-dimensional surface (the screen). There are two primary types of projections: parallel and perspective.

Types of Projections

  1. Parallel Projections: In parallel projection, the projection lines are parallel to each other, resulting in a scale that remains consistent regardless of the object's distance from the viewer. This type of projection is useful for technical drawings and architectural plans.

    • Oblique Projections: A subtype of parallel projection, where the projection lines are not perpendicular to the projection plane. Common forms include:

      • Cavalier Projection: The depth is represented without distortion, maintaining the true length.
      • Cabinet Projection: The depth is halved, creating a more realistic appearance.
    • Orthographic Projections: This projection maintains the true shape and size of the object, allowing for accurate measurements. Variations include:

      • Isometric Projection: Displays three dimensions equally, with angles of 120 degrees between axes.
      • Diametric Projection: Two dimensions are represented at a scale of 1, while the third is scaled to provide depth.
      • Trimetric Projection: All three axes are displayed at different angles and scales, providing a more dynamic view.

Perspective Projections

In perspective projection, the projection lines converge at a single point (the viewer’s eye or camera), creating a sense of depth and realism. This type of projection mimics how humans perceive the world, where distant objects appear smaller.

  1. Vanishing Points: The concept of vanishing points is critical in perspective projection, where parallel lines converge at a point on the horizon. There are three main types based on the number of vanishing points:
    • One-Point Perspective: All lines converge to a single point. This technique is often used for scenes with a single viewpoint, such as hallways or roads.
    • Two-Point Perspective: Lines converge to two points on the horizon, commonly used for corner views of buildings and objects.
    • Three-Point Perspective: This projection involves three vanishing points, often used for extreme angles or views from above or below an object.

Applications of Projections

  • Architectural Visualization: Projections are widely used in architecture to create drawings that accurately represent the dimensions and layouts of buildings.
  • Video Games and Simulation: Perspective projections enhance realism in video games, allowing players to navigate immersive environments effectively.