COVERED T5OPICES OF UNIT 3 AND 4
Unit III: Two Dimensional Geometric Transformations Hours: Basic transformations: Translation, Scaling, Rotation , Matrix representation and Homogeneous Coordinates Composite transformation Other transformations: Reflection and Shear
Unit IV: Two-Dimensional Viewing and Clipping Viewing transformation pipeline and Window to Viewport coordinate transformation , Clipping operations: Point clipping, Line clipping algorithms: Cohen-Sutherland, Liang: Barsky, Polygon Clipping Algorithms: Sutherland-Hodgeman, Weiler-Atherton.
Unit 3
- Two Dimensional Geometric Transformations:
Two-dimensional geometric transformations are fundamental operations in computer graphics that involve changing the position, size, and orientation of objects in a 2D space. These transformations are applied to graphical objects, such as points, lines, and polygons, to manipulate their appearance on a screen. There are several types of 2D transformations, each serving a specific purpose:
Translation:
Rotation:
Scaling:
Here, scale_factor_x
and scale_factor_y
represent the scaling factors along the x and y axes, respectively.
Shearing:
- Reflection:
These transformations are fundamental in computer graphics, forming the basis for various advanced techniques, including computer-aided design, animation, and image processing. Understanding these concepts is crucial for anyone working with computer graphics applications.
Matrix Representation:
Matrix representation is a widely used technique in computer graphics to perform various transformations efficiently, including translation, rotation, scaling, and shearing. These transformations can be represented as matrices, making it easier to apply multiple transformations sequentially. In 2D graphics, a point (x, y) can be represented as a column matrix:
To perform transformations using matrices, you can represent translation, rotation, scaling, and shearing operations as matrices:
Translation Matrix (T):
Translation matrix T can be used to translate a point P by (, ) using the following equation:
Rotation Matrix (R):
Rotation matrix R can be used to rotate a point P by an angle around the origin (0, 0) using the equation:
Scaling Matrix (S):
Scaling matrix S can be used to scale a point P by factors and along the x and y axes, respectively, using the equation:
Shearing Matrix (Sh):
Shearing matrix Sh can be used to shear a point P by factors and along the x and y axes, respectively, using the equation:
Using these matrices, you can combine transformations by multiplying the respective transformation matrices and applying the resulting matrix to a point or object.
Homogeneous Coordinates:
Homogeneous coordinates are a system used in computer graphics to represent points in higher-dimensional spaces, making it easier to perform transformations, especially perspective transformations. In 2D graphics, a point (x, y) can be represented in homogeneous coordinates as (x, y, 1).
The advantage of homogeneous coordinates is that they allow you to represent translation as a matrix multiplication. For example, a point (x, y) can be represented in homogeneous coordinates as a 3x1 matrix:
The translation matrix for 2D homogeneous coordinates is:
To apply translation using homogeneous coordinates, you can multiply the translation matrix by the homogeneous coordinate matrix to get the transformed point :
Homogeneous coordinates are also useful for performing perspective transformations and other 3D graphics operations. They provide a more elegant and convenient way to handle transformations in higher-dimensional spaces.
Composite Transformations:
Composite transformations involve combining multiple basic transformations (such as translation, rotation, scaling, and shearing) to create more complex transformations. This is achieved by multiplying the transformation matrices together in a specific order. When combining transformations, the order of operations matters. For example, translating an object and then rotating it produces a different result than rotating the object and then translating it.
To perform composite transformations, you can multiply the individual transformation matrices in the reverse order of how you want the transformations to be applied. For example, if you want to first rotate an object and then translate it, you would multiply the translation matrix with the rotation matrix.
You can then apply this composite matrix to a point or object to perform both translation and rotation simultaneously.
Other Transformations:
In addition to the basic transformations (translation, rotation, scaling, shearing, and reflection) and composite transformations, there are several other advanced transformations used in computer graphics:
Affine Transformation:
Affine transformations include translation, rotation, scaling, and shearing. Affine transformations preserve points, straight lines, and planes. The transformation matrix for an affine transformation in 2D looks like this:- Perspective Transformation:Perspective transformations are used to create a sense of depth in 3D graphics. They involve transforming 3D points onto a 2D plane, considering the viewer's perspective. The perspective transformation matrix is more complex and is used to create realistic 3D scenes.
- Curved Path Transformations:Transformations can be applied along curved paths, allowing objects to move or deform along a specified curve. These transformations are essential for animations and simulations where natural movements are required.
- Texture Transformations:Texture transformations involve mapping a 2D texture onto a 3D surface. These transformations are used to adjust the appearance of textures on 3D models, ensuring they wrap around surfaces correctly.
- Morphing:Morphing transformations involve smoothly transforming one object into another. This technique is often used in animations, where one shape transitions into another shape seamlessly over time.
Each of these transformations plays a vital role in computer graphics, enabling the creation of diverse and visually appealing graphics and animations. Understanding these techniques allows graphics programmers and artists to create complex and realistic digital imagery.
Reflection:
Reflection in computer graphics involves flipping an object over a line, known as the mirror line or reflection axis. It is a transformation that creates a mirror image of an object. In 2D graphics, reflection can occur over the x-axis, y-axis, or an arbitrary line in the plane.
Reflection Over the X-Axis: When reflecting a point (x, y) over the x-axis, the y-coordinate changes sign while the x-coordinate remains the same. The reflection transformation can be represented as:
Reflection Over the Y-Axis: When reflecting a point (x, y) over the y-axis, the x-coordinate changes sign while the y-coordinate remains the same. The reflection transformation can be represented as:
Reflection Over an Arbitrary Line: When reflecting a point (x, y) over an arbitrary line with equation , the reflection transformation involves finding the perpendicular distance () of the point to the line and then using this distance to find the reflected point. The transformation equations are:
Shear:
Shearing is a transformation that distorts the shape of an object by shifting points in a particular direction. There are two types of shear transformations: horizontal shear and vertical shear.
Horizontal Shear: Horizontal shear shifts points in a horizontal direction. When shearing a point (x, y) horizontally by a shear factor (), the transformation equations are:
Vertical Shear: Vertical shear shifts points in a vertical direction. When shearing a point (x, y) vertically by a shear factor (), the transformation equations are:
Shearing is often used in computer graphics for creating various effects, such as slanting text, creating 3D projections, and simulating motion blur.
Understanding these concepts and their mathematical representations is crucial for anyone working with computer graphics, as they form the basis for more complex transformations and effects in digital imaging.
Unit 4
Two-Dimensional Viewing and Clipping
Two-Dimensional Viewing involves the process of mapping a 2D scene onto the 2D viewport (the visible portion of the screen). The goal is to define a mapping function that transforms the coordinates of objects in the world space to the coordinates on the screen (or window) space. This process includes defining the view volume, which determines what portion of the world is visible and how it should be mapped to the screen.
- Window-to-Viewport Transformation:After defining the view volume, the next step is to transform the coordinates from the window space (also known as the normalized device coordinates) to the viewport space (pixel coordinates on the screen). This transformation involves mapping the window boundaries to the screen pixel boundaries.
- Viewport Mapping:The viewport mapping process scales and translates the normalized device coordinates to fit within the actual screen resolution. It involves converting coordinates from the normalized device coordinate system (ranging from -1 to 1) to the pixel coordinate system (typically ranging from 0 to the screen width/height).
Clipping in 2D Graphics:
Clipping is the process of removing objects or parts of objects that are outside the view volume or viewport boundaries. It is essential for optimizing rendering and ensuring that only the visible portion of objects is displayed on the screen.
- Point Clipping:Points lying outside the view volume are removed before rendering. If a point's coordinates are outside the defined view volume, it is clipped and not displayed.
- Line Clipping:Lines can be clipped against the view volume boundaries using algorithms like Cohen-Sutherland or Liang-Barsky line clipping. These algorithms efficiently determine the portion of a line segment that lies inside the view volume.
- Polygon Clipping:Polygon clipping involves removing parts of polygons that are outside the view volume. Sutherland-Hodgman polygon clipping algorithm is commonly used for this purpose. It clips polygons against each view volume boundary, producing a new polygon that fits inside the view volume.
Viewing transformation pipeline and Window to Viewport coordinate transformation.
Viewing Transformation Pipeline:
The viewing transformation pipeline is a series of transformations applied to objects or scenes in a 3D world to map them onto a 2D viewport for display. This pipeline involves several steps:
Modeling Transformation: Objects in the 3D world are transformed from their local coordinate systems to a global or world coordinate system. Modeling transformations include translation, rotation, scaling, and other transformations that position and orient objects in the world.
Viewing Transformation (or Camera Transformation): The viewing transformation, also known as the camera transformation, positions and orients the virtual camera in the world. This transformation simulates the view from the camera's perspective. It involves transformations like translation, rotation, and scaling, allowing the camera to move, rotate, and zoom within the 3D scene.
Projection Transformation: The projection transformation maps the 3D scene onto a 2D plane, simulating the perspective effect. Common types of projections include perspective projection and orthographic projection. Perspective projection creates a sense of depth, while orthographic projection removes perspective, creating a more schematic, isometric view.
Viewport Transformation: The 2D projection of the scene is then mapped onto the 2D viewport, which is the portion of the screen where the final image will be displayed. This transformation maps the 2D projection to screen coordinates, adjusting for the screen's resolution and dimensions.
Window to Viewport Coordinate Transformation:
Once the viewing transformation pipeline is applied, the resulting 2D image is often referred to as the "window." To display this window on the screen, a transformation is needed to map the window coordinates to the viewport coordinates.
Window Coordinates: Window coordinates represent the visible portion of the scene after all the transformations are applied. These coordinates are typically normalized and range from -1 to 1 along each axis.
Viewport Coordinates: Viewport coordinates represent the actual screen pixels where the final image will be displayed. These coordinates typically range from 0 to the screen width/height along each axis.
The transformation from window coordinates to viewport coordinates involves scaling and translating the window coordinates to fit within the screen resolution. The viewport transformation can be represented by the following equations for x and y coordinates:
These equations map the normalized window coordinates (-1 to 1) to pixel coordinates on the screen (0 to screen width/height) and ensure that the final image is displayed correctly within the specified viewport.
Clipping operations:
Clipping operations in computer graphics involve removing or discarding parts of geometric objects that are outside the view volume or viewport boundaries. Clipping ensures that only the visible portions of objects are displayed on the screen. There are several types of clipping operations used in computer graphics:
- Point Clipping:Point clipping involves determining whether a point is inside or outside the view volume. If a point is outside the view volume, it is removed from further processing and not displayed.
- Line Clipping:Line clipping is the process of determining which parts of a line segment lie inside the view volume and should be displayed. Common line clipping algorithms include:
- Cohen-Sutherland Algorithm: Divides the 2D space into nine regions and efficiently determines the intersection points of a line with the view volume boundaries.
- Liang-Barsky Algorithm: Clips a line segment against each edge of the view volume and computes parametric values to find the intersection points.
- Polygon Clipping:Polygon clipping involves removing portions of a polygon that are outside the view volume. Common polygon clipping algorithms include:
- Sutherland-Hodgman Algorithm: Clips a polygon against each edge of the view volume by iteratively computing intersection points.
- Weiler-Atherton Algorithm: Handles complex polygons by computing the intersection points and forming new polygons based on the intersections.
- Area Clipping:Area clipping involves clipping an area, defined by multiple line segments or curves, against the view volume boundaries. This technique is useful for complex shapes that cannot be represented as simple polygons.
- Backface Culling:Backface culling is a technique used in 3D graphics to improve rendering performance. It involves removing polygons that are not visible from the camera's viewpoint. Backface culling relies on the order of vertices in a polygon and the camera's viewing direction.
- Clipping in Homogeneous Coordinates:Homogeneous coordinates are often used for 3D clipping operations, especially in perspective projection. Clipping in homogeneous coordinates simplifies the math involved in the clipping process.
Clipping is an essential step in the graphics rendering pipeline, ensuring that only the visible parts of objects are sent to subsequent stages, such as projection and rasterization. Efficient clipping algorithms are crucial for real-time graphics applications, enabling smooth and realistic rendering of 3D scenes on computer screens.
- Point Clipping:
Point clipping involves determining whether a point is inside or outside a specified clipping region (such as a rectangular window). Points outside the region are discarded.
Cohen-Sutherland Algorithm (Point Clipping):
The Cohen-Sutherland algorithm divides the 2D space into nine regions using a binary code (outcodes) representing the point's position relative to the clipping window. Here's how it works:
Assign Outcodes: Determine the outcode for the point based on its position relative to the clipping window:
- Left: bit 1 set
- Right: bit 2 set
- Bottom: bit 4 set
- Top: bit 8 set
Clip the Point:
- If both points have a zero outcode, they are inside the window and can be kept.
- If the bitwise AND of the two outcodes is not zero, the points are on different sides of a clip boundary, and the segment might cross the boundary.
Repeat the following steps until the segment is either entirely inside or outside the window:
- Find the intersection of the segment with the boundary.
- Replace one of the endpoints with the intersection point.
- Recalculate the outcode for the updated endpoint.
- Repeat the process until the segment is either completely inside or outside the window.
Line Clipping:
Line clipping involves determining which parts of a line segment lie inside the clipping region.
Liang-Barsky Algorithm (Line Clipping):
The Liang-Barsky algorithm provides an efficient way to clip a line segment against a rectangular clipping window.
Given a line defined by two endpoints and , the algorithm involves the following steps:
Parameter Calculation: Calculate four parameters , , , and based on the line equation :
Clip Against Left Edge: If , calculate . If , calculate . If , the line is outside the window and can be rejected.
Clip Against Right Edge: If , calculate . If , the line is outside the window and can be rejected.
Clip Against Bottom Edge: If , calculate . If , calculate . If , the line is outside the window and can be rejected.
Clip Against Top Edge: If , calculate . If , the line is outside the window and can be rejected.
If the line survives all these clipping tests, it can be drawn from the point to after calculating the intersection points using the parameter values and .
These algorithms are essential for efficiently rendering lines and points on a computer screen while discarding parts of the geometry that lie outside the visible region.
Cohen-Sutherland Line-Clipping Algorithm:
1. Assign Outcodes:
Each endpoint of the line is assigned an outcode based on its position relative to the clipping window:
- Bit 1: Left
- Bit 2: Right
- Bit 3: Bottom
- Bit 4: Top
For example:
- If a point is to the left of the window, bit 1 is set to 1.
- If a point is to the right of the window, bit 2 is set to 1.
- If a point is below the window, bit 3 is set to 1.
- If a point is above the window, bit 4 is set to 1.
2. Check Visibility:
- If both outcodes are 0000 (inside the window), the line is entirely inside and can be drawn.
- If the bitwise AND of the two outcodes is not 0000, the line may partially or completely lie outside the window.
3. Clip the Line:
If the line is not completely inside the window, clip it against the window boundaries iteratively:
- Calculate the intersection of the line with the window boundaries.
- Replace the endpoint outside the window with the intersection point.
- Recalculate the outcode for the updated endpoint.
- Repeat these steps until the line is either completely inside the window or entirely outside the window.
The Cohen-Sutherland algorithm efficiently determines the intersection points of a line with the clipping window boundaries, allowing for the partial or complete removal of line segments that are outside the visible region.
This algorithm is widely used due to its simplicity and efficiency, especially in applications where line visibility against a rectangular clipping window needs to be quickly determined.
Liang-Barsky
The Liang-Barsky line-clipping algorithm is another popular method used for clipping lines in computer graphics against a rectangular clipping window. It is more efficient than the Cohen-Sutherland algorithm as it avoids the need for repeated calculations for each clipping boundary. Here's how the Liang-Barsky algorithm works:
Liang-Barsky Line-Clipping Algorithm:
1. Parameter Calculation:
Given a line defined by two endpoints and , calculate the parameters , , , and based on the line equation :
2. Clip the Line:
- Check against left edge:
- If :
- Calculate
- If , update (left intersection parameter)
- If :
- Check against right edge:
- If :
- Calculate
- If , update (right intersection parameter)
- If :
- Check against bottom edge:
- If :
- Calculate
- If , update (bottom intersection parameter)
- If :
- Check against top edge:
- If :
- Calculate
- If , update (top intersection parameter)
- If :
3. Draw the Clipped Line:
- If , the line is entirely outside the window and can be discarded.
- If , calculate the intersection points:
- (entry point)
- (exit point)
- Draw the line segment from to
The Liang-Barsky algorithm efficiently calculates the intersection parameters and determines the visible portion of the line without requiring multiple tests against each clipping boundary, making it faster and more effective than some other line-clipping algorithms.
Polygon Clipping Algorithms
Polygon clipping algorithms are used to clip polygons against a clipping window or another polygon to find the visible portion of the polygon. There are several polygon clipping algorithms, each with its own approach and efficiency. Here are a few common ones:
Sutherland-Hodgman Polygon Clipping Algorithm:
The Sutherland-Hodgman algorithm clips a polygon against a rectangular clipping window. Here's how it works:
Clip against Left Edge: For each edge (V[i], V[i+1]) of the polygon, if V[i] is inside the window and V[i+1] is outside, add the intersection point of the edge and the left window boundary to the output list.
Clip against Right Edge: For each edge (V[i], V[i+1]) of the intermediate polygon, if V[i] is outside and V[i+1] is inside, add the intersection point of the edge and the right window boundary to the output list.
Clip against Bottom Edge: For each edge (V[i], V[i+1]) of the intermediate polygon, if V[i] is inside and V[i+1] is outside, add the intersection point of the edge and the bottom window boundary to the output list.
Clip against Top Edge: For each edge (V[i], V[i+1]) of the intermediate polygon, if V[i] is outside and V[i+1] is inside, add the intersection point of the edge and the top window boundary to the output list.
The resulting list of vertices forms the clipped polygon.
Weiler-Atherton Polygon Clipping Algorithm:
The Weiler-Atherton algorithm clips a polygon against another polygon. It works as follows:
Marking Intersections: Find intersection points between the subject polygon and the clipping polygon. Mark the vertices of both polygons as "entry" or "exit" points based on the order in which they are encountered.
Clipping: Traverse the marked vertices and create the output polygon:
- When an entry point is encountered in the subject polygon, traverse the clipping polygon until the corresponding exit point is found. Add the vertices between the entry and exit points to the output polygon.
- When an entry point is encountered in the clipping polygon, traverse the subject polygon until the corresponding exit point is found. Discard the vertices between the entry and exit points.
The resulting output polygon is the clipped polygon.
Greiner-Hormann Polygon Clipping Algorithm:
The Greiner-Hormann algorithm is an extension of the Weiler-Atherton algorithm and handles complex polygons with holes. It is more robust and versatile, but also more complex to implement.
These algorithms are fundamental for rendering complex scenes where objects need to be clipped against windows, viewports, or other objects to determine the visible portions. Implementing these algorithms correctly is crucial for accurate and efficient computer graphics rendering.
Sutherland-Hodgman
The Sutherland-Hodgman Polygon Clipping Algorithm is used to clip a polygon against a rectangular clipping window. It works by iteratively cutting the polygon against each edge of the clipping window. Here's how the algorithm works:
Input:
- Subject Polygon: The polygon to be clipped.
- Clipping Window: The rectangular window used for clipping.
Initialization: Initialize an empty list to store the vertices of the clipped polygon.
Clip Against Left Edge: For each edge (V[i], V[i+1]) of the subject polygon, if V[i] is inside the window and V[i+1] is outside, add the intersection point of the edge and the left window boundary to the output list.
Clip Against Right Edge: For each edge (V[i], V[i+1]) of the intermediate polygon, if V[i] is outside and V[i+1] is inside, add the intersection point of the edge and the right window boundary to the output list.
Clip Against Bottom Edge: For each edge (V[i], V[i+1]) of the intermediate polygon, if V[i] is inside and V[i+1] is outside, add the intersection point of the edge and the bottom window boundary to the output list.
Clip Against Top Edge: For each edge (V[i], V[i+1]) of the intermediate polygon, if V[i] is outside and V[i+1] is inside, add the intersection point of the edge and the top window boundary to the output list.
The resulting list of vertices forms the clipped polygon.
The Sutherland-Hodgman algorithm clips the polygon against each edge of the clipping window one by one, handling both convex and concave polygons. It can handle complex polygons and is relatively easy to implement, making it a popular choice for simple clipping tasks. However, it becomes inefficient for very complex scenes or polygons with a large number of vertices.
Weiler-Atherton.
The Weiler-Atherton Polygon Clipping Algorithm is used to clip a subject polygon against a clipping polygon, and it handles complex polygons with holes. The algorithm works by finding intersection points between the subject and clipping polygons and then constructing the resulting clipped polygons. Here's how the Weiler-Atherton algorithm works:
Marking Intersections:
- Find all intersection points between the edges of the subject polygon and the clipping polygon.
- Mark the vertices of both polygons as either "entry" or "exit" points based on the order in which they are encountered along the edges.
Clipping:
- Traverse the edges of the subject polygon.
- When an "entry" point is encountered in the subject polygon, traverse the edges of the clipping polygon until the corresponding "exit" point is found. Add the vertices between the entry and exit points to the output list.
- When an "entry" point is encountered in the clipping polygon, traverse the edges of the subject polygon until the corresponding "exit" point is found. Discard the vertices between the entry and exit points.
Handle Holes:
- If the subject polygon has holes, repeat the intersection marking and clipping process for each hole, treating the outer boundary of the hole as the clipping polygon.
The resulting output list(s) represent the clipped polygons.
The Weiler-Atherton algorithm provides a systematic approach to handling complex polygons and polygons with holes. It accurately clips polygons and produces the correct output even in the presence of holes and overlapping edges. However, the algorithm can be relatively complex to implement compared to simpler algorithms like Sutherland-Hodgman for basic polygon clipping tasks.