0% found this document useful (0 votes)
15 views

2nd Unit - CG

The document discusses various 2D geometric transformations including translation, rotation, scaling, reflection, and shear. It explains how to represent these transformations using matrices and how to combine multiple transformations using composite or compound transformations by multiplying the matrices in the proper order.

Uploaded by

Ashwin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

2nd Unit - CG

The document discusses various 2D geometric transformations including translation, rotation, scaling, reflection, and shear. It explains how to represent these transformations using matrices and how to combine multiple transformations using composite or compound transformations by multiplying the matrices in the proper order.

Uploaded by

Ashwin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Page 1 of 11

2. 2D Transformation, Windowing and Clipping:

Geometric Transformation – Translation – Rotation –


Scaling:
Geometric transformations, including translation, rotation, and scaling, are fundamental operations in
computer graphics, computer vision, and various fields of mathematics and engineering. They are
used to manipulate the position, orientation, and size of objects in a 2D or 3D space. Let's look at
each of these transformations individually:

1. Translation: Translation is the process of moving an object from one location to another. In
2D, it involves shifting the object by a specified distance in the x and y directions. In 3D, you
would also include a z-component. The transformation matrix for a 2D translation is typically
represented as:
Copy code
| 1 0 dx | | 0 1 dy | | 0 0 1 |
Here, (dx, dy) represents the translation in the x and y directions, respectively. This matrix can
be multiplied with the coordinates of the object to achieve the translation.
2. Rotation: Rotation is the transformation that changes the orientation of an object. In 2D, a
rotation involves specifying an angle (θ) by which the object should be rotated
counterclockwise. The transformation matrix for a 2D rotation is typically represented as:
scssCopy code
| cos (θ) -sin (θ) 0 | | sin (θ) cos (θ) 0 | | 0 0 1 |
You can use this matrix to rotate the object around the origin (0, 0) by multiplying it with the
object's coordinates.
3. Scaling: Scaling changes the size of an object. In 2D, scaling involves specifying scaling
factors (sx, sy) to increase or decrease the object's size along the x and y axes. The
transformation matrix for a 2D scaling is usually represented as:
Copy code
| sx 0 0 | | 0 sy 0 | | 0 0 1 |
This matrix can be multiplied with the object's coordinates to achieve scaling. A scaling factor
greater than 1 increases the size, while a factor less than 1 reduces the size.

To combine multiple transformations (e.g., translation followed by rotation and then scaling), you can
multiply the transformation matrices in the desired order. The order in which transformations are
applied can affect the final result, so be mindful of the sequence.
Page 2 of 11

In 3D, similar transformations can be applied, but the transformation matrices become 4x4 matrices
to accommodate the additional dimension (z). The principles are the same, but the matrices are more
complex.

These transformations are fundamental in computer graphics for rendering and transforming
objects, in computer vision for image processing, and in various other applications involving spatial
manipulation of data.

Reflection and Shear matrix representations:


Reflection and shear are additional geometric transformations used in computer graphics and
mathematics. Let's explore their matrix representations:

1. Reflection:
Reflection is a transformation that flips an object over a specified axis. In 2D, you can perform
reflection over the x-axis, y-axis, or any other line. The matrix representation of a 2D
reflection over the x-axis is as follows:
For reflection over the x-axis:
Copy code
| 1 0 | | 0 -1 |
For reflection over the y-axis:
Copy code
| -1 0 | | 0 1 |
To perform reflection over an arbitrary line with a slope (m), you can use the following
formula:
Copy code
| 1 - m^2 2m | | 2m 1 - m^2 |
Here, (1 - m^2) is the cosine of twice the angle between the line of reflection and the x-axis,
and 2m is the sine of twice the angle.
In 3D, you can perform reflections over planes using appropriate transformation matrices.
2. Shear:
Shear is a transformation that skews or distorts an object by displacing points in one
direction. There are different types of shear, including shear along the x-axis, y-axis, or
arbitrary directions. The matrix representation for a 2D shear along the x-axis and y-axis is as
follows:
For shear along the x-axis:
Copy code
| 1 shx | | 0 1 |
For shear along the y-axis:
Copy code

| 1 0 | | shy 1 |
Page 3 of 11

Here, shx represents the shear factor along the x-axis, and shy represents the shear factor
along the y-axis.
To perform shear along an arbitrary direction (shear angle θ), you can use the following
formula:
scssCopy code
| 1 tan (θ) | | tan (θ) 1 |
In 3D, shear can be applied in the same way, but the matrices become 4x4 to accommodate
the additional dimension.

These transformations, including reflection and shear, are essential in computer graphics, allowing
you to create various effects and manipulate objects in different ways. The specific transformation
matrix you use depends on the desired transformation and axis of operation.

Homogeneous Co-ordinates:
Homogeneous coordinates are a mathematical representation used in projective geometry and
computer graphics to represent points and transformations in a convenient and unified manner.
They are especially useful when working with perspective transformations, including projections in
3D graphics.

In homogeneous coordinates, a point in 2D or 3D space is represented as a set of four (for 2D) or


five (for 3D) coordinates, typically denoted as (x, y, w) for 2D or (x, y, z, w) for 3D. The "w" or "z"
component is a scaling factor that brings the other coordinates back to Cartesian coordinates (x, y, z)
when dividing through by it. The homogeneous coordinates of a point (x, y) in 2D or (x, y, z) in 3D
are typically written as (x, y, w) or (x, y, z, w), with w being a nonzero value.

The main benefits of using homogeneous coordinates are:

1. Convenience in Representing Points and Vectors: Homogeneous coordinates allow you to


represent points, vectors, and directions using the same mathematical structure. This
simplifies the representation of translations and perspective projections.
2. Affine Transformations: Homogeneous coordinates provide a unified way to represent and
combine affine transformations (translations, rotations, scalings, shears) as matrix
multiplications.
3. Perspective Transformations: They are particularly useful for representing and working with
perspective transformations, such as perspective projections in 3D graphics.
4. Infinity and Projective Geometry: Homogeneous coordinates naturally accommodate
points at infinity, which is essential for projective geometry. For example, parallel lines
intersect at infinity in projective geometry, and homogeneous coordinates can represent
these points.
Page 4 of 11

In 2D, the conversion between homogeneous coordinates (x, y, w) and Cartesian coordinates (x', y') is
achieved by dividing through by the w component:

x' = x / w y' = y / w

In 3D, the conversion is similar:

x' = x / w y' = y / w z' = z / w

When w (or z in 3D) is equal to 1, the point is in standard Cartesian coordinates. When w is not equal
to 1, it represents a point in homogeneous coordinates.

In summary, homogeneous coordinates are a powerful tool for representing and manipulating
points, transformations, and projections in computer graphics, computer vision, and projective
geometry. They simplify the handling of various mathematical operations and are especially useful
when dealing with perspective transformations.

Composite Transformation:
A composite transformation, also known as a composed transformation or a compound
transformation, is a combination of multiple individual transformations applied to an object or a set
of coordinates. These individual transformations can include translations, rotations, scalings, shears,
reflections, or any other geometric transformation. When combined, they create a single
transformation that represents the cumulative effect of the individual transformations applied in a
specific order.

Composite transformations are often used in computer graphics, computer-aided design, animation,
and other fields to manipulate objects, create complex movements, and control the transformation
of elements in a scene. The order in which individual transformations are applied can significantly
impact the final result, so it's important to consider the sequence carefully.

To create a composite transformation, you typically multiply the individual transformation matrices in
the order you want them to be applied. The order is important because matrix multiplication is not
commutative; changing the order of multiplication will yield a different result.

For example, suppose you want to perform a composite transformation that involves a sequence of
translation, rotation, and scaling. You can represent this as follows:

1. Translation matrix (T) to move the object to a new position.


2. Rotation matrix (R) to change its orientation.
3. Scaling matrix (S) to adjust its size.
Page 5 of 11

The composite transformation matrix (C) is the result of multiplying these matrices in the desired
order:

C=T*R*S

You apply the composite transformation matrix C to the object's coordinates to achieve the
combined effect of translation, rotation, and scaling.

It's important to note that the order in which you multiply the matrices matters. In the example
above, the translation is applied first, followed by rotation, and then scaling. If you were to change
the order of multiplication, you would get a different result. The choice of order depends on the
specific requirements of the transformation you want to achieve.

Composite transformations are a powerful tool for creating complex transformations in computer
graphics and animation, allowing you to control the position, orientation, and size of objects in a
scene with precision.

Raster methods for geometric transformations:


Raster methods for geometric transformation are techniques used to apply geometric
transformations, such as translation, rotation, scaling, and shearing, to digital images. These methods
are essential in computer graphics and image processing when working with rasterized images,
which are composed of discrete pixels. Here are some common raster methods for geometric
transformation:

1. Pixel Replication or Nearest-Neighbor Interpolation:


 This method involves simply mapping each pixel in the original image to its
corresponding position in the transformed image. The pixel values of the original
image are directly copied to the new position. If the transformation involves scaling,
this method can result in a blocky appearance.
 It is computationally efficient but may not provide the best image quality, especially
when upscaling.
2. Bilinear Interpolation:
 Bilinear interpolation is used to calculate the pixel values for the transformed image
by taking weighted averages of the pixel values from the nearest neighboring pixels
in the original image.
 It results in smoother and more visually appealing transformations, particularly for
scaling and rotation. However, it is computationally more expensive than pixel
replication.
3. Bicubic Interpolation:
 Bicubic interpolation is an even higher-order interpolation method that provides
better image quality but is computationally more intensive than bilinear
interpolation. It uses a cubic polynomial to interpolate pixel values.
 Bicubic interpolation can help reduce aliasing artifacts and improve image sharpness.
Page 6 of 11

4. Affine Transformations:
 For affine transformations (combinations of translation, rotation, scaling, shearing),
you can use linear algebra methods to transform points and interpolate pixel values
in the transformed image.
 These methods typically involve matrix multiplication and can handle multiple
transformations in a single pass.
5. Warping and Mesh Deformation:
 In some cases, such as non-linear distortions, warping or mesh deformation
techniques are used. These involve defining control points in the original image and
specifying their positions in the transformed image. Interpolation is used to
determine the pixel values at other points.
 These methods are versatile but can be computationally expensive, especially for
complex transformations.
6. Texture Mapping:
 Texture mapping is often used in 3D computer graphics to apply textures to 3D
models. It can involve mapping a 2D texture onto a 3D surface with perspective
correction.
 These methods are essential for creating realistic 3D graphics and involve various
interpolation and transformation techniques.
7. Hardware Acceleration:
 Many modern graphics hardware and GPUs include dedicated hardware for
geometric transformations and rasterization, making real-time rendering of
transformed images and 3D graphics possible.

The choice of the appropriate raster method depends on the specific transformation, image quality
requirements, computational resources, and real-time rendering constraints. In practice, a
combination of these methods may be used for different stages of the rendering pipeline in
computer graphics and image processing.

Window and Viewport – Clipping process – Point Clipping,


Line Clipping, Text Clipping:
Window and viewport are concepts used in computer graphics to define the area of the screen or
image where objects are displayed and rendered. Clipping is a process that involves determining
which parts of objects or graphics elements should be visible within the defined window (also known
as a clipping window) and then mapping those visible parts to the screen or viewport. Clipping is
essential for efficiently rendering graphics and ensuring that only the visible portions of objects are
drawn.
Page 7 of 11

Here's an overview of the window, viewport, and different types of clipping processes:

1. Window and Viewport:

 Window: The window is an abstract, user-defined region in world coordinates that specifies
the portion of the scene or graphical content you want to display.
 Viewport: The viewport is a rectangular region in screen or device coordinates where the
contents of the window are actually displayed. It defines the area on the screen where the
graphics will be rendered.

2. Clipping Process: The clipping process determines which parts of objects are visible within the
window and then maps those visible parts to the viewport for rendering. Clipping can be applied to
various types of graphics elements, including points, lines, and text.

Point Clipping:

 Point clipping involves determining if a point is inside or outside the window.


 If a point is inside the window, it is drawn within the viewport. If it's outside, it is not drawn.

Line Clipping:

 Line clipping deals with lines that may intersect the window boundaries.
 Common line clipping algorithms include Cohen-Sutherland, Liang-Barsky, and Sutherland-
Hodgman.
 These algorithms categorize line segments as either inside, outside, or partially inside the
window and then clip the lines accordingly.

Text Clipping:

 Text clipping is a specific case where text or characters need to be clipped to ensure they fit
within the window and viewport.
 For text, a simple approach is to ensure that the entire character or text string is within the
window before rendering it.

The specific clipping algorithm and process used can vary based on the requirements of the
application, performance considerations, and the type of graphics being displayed. More complex
scenes may involve multiple layers of clipping, such as clipping objects within a window and then
mapping the window contents to the viewport.

Clipping is an essential step in computer graphics for rendering efficiency and ensuring that only the
visible parts of objects are drawn, reducing the computational load and improving the overall visual
quality of the rendered graphics.
Page 8 of 11

Line Clipping Techniques – Cohen Sutherland line clipping


algorithm:
The Cohen-Sutherland line clipping algorithm is a popular and simple method used for clipping line
segments against a rectangular clipping window. It divides the 2D space into nine regions, or
"outcodes," and uses these outcodes to quickly determine if a line segment lies entirely inside,
outside, or partially inside a rectangular window. If the line segment is partially inside the window,
the algorithm computes the intersection points with the window boundaries to clip the line.

Here are the key steps of the Cohen-Sutherland line clipping algorithm:

1. Define the Clipping Window:


 Specify the rectangular clipping window, which is defined by its left, right, top, and
bottom boundaries. This window represents the region of the screen within which the
line segments will be clipped.
2. Assign Outcodes:
 Divide the 2D space into nine regions based on the clipping window. Assign unique
binary outcodes to each region:
 Top-Left: 1001
 Top: 1000
 Top-Right: 1010
 Left: 0001
 Inside: 0000
 Right: 0010
 Bottom-Left: 0101
 Bottom: 0100
 Bottom-Right: 0110
3. Compute Outcodes for Line Endpoints:
 For each endpoint of the line segment, determine its outcode based on its relative
position to the clipping window. The outcode for a point is determined by comparing
its x and y coordinates with the window boundaries.
4. Perform Clipping:
 Check the relative positions of the two endpoints' outcodes to the window:
 If both endpoints have outcodes equal to 0000 (inside), the line segment is
entirely inside the window and should be drawn.
 If the logical AND of the two endpoints' outcodes is not equal to 0000, the
line segment is entirely outside the window and should be discarded.
 If the line segment is partially inside the window, find the intersection points
of the line with the window boundaries and replace the out-of-bounds
endpoint(s) with the intersection point(s).
 Repeat these steps until the line segment is either entirely inside, entirely
outside, or fully clipped.
Page 9 of 11

5. Draw or Use Clipped Line:


 After the line segment has been processed, it is either drawn if it is entirely inside the
window or clipped and used if it is partially inside the window.

The Cohen-Sutherland algorithm efficiently reduces the number of calculations required for line
clipping by using the binary outcodes and early-rejecting line segments that are entirely outside the
clipping window.

This algorithm is relatively simple and works well for rectangular clipping windows. However, it may
require additional work or other algorithms for more complex clipping shapes or polygons.

Midpoint Subdivision Algorithm – Area Clipping –


Sutherland and Hodgman polygon clipping algorithm:
The Midpoint Subdivision Algorithm is a technique used for subdividing a line segment into smaller
segments while preserving the original line's slope and characteristics. This algorithm is often
employed in computer graphics for tasks such as scanline rendering, hidden line removal, and other
geometric operations.

The basic idea of the Midpoint Subdivision Algorithm is to divide a line segment into two smaller
segments at the midpoint of the original line. The algorithm takes advantage of the symmetry of the
line with respect to its midpoint to simplify the division process. Here are the steps to implement the
algorithm:

1. Sutherland-Hodgman Polygon Clipping Algorithm:


The Sutherland-Hodgman algorithm clips a polygon against a convex clipping window. Here
are the key steps of the algorithm:
a. Initialize a list of vertices for the resulting clipped polygon, starting with an empty list.
b. For each edge of the clipping window (defined by two successive vertices), clip the current
polygon against that edge.
c. For each input vertex in the polygon, perform the following:
i. Check if the vertex is inside the clipping window (inside the half-space defined by the
clipping edge). If it is, add it to the list of clipped vertices.
ii. If the vertex is outside the clipping edge, check the previous vertex. If the previous vertex
was inside the clipping window, compute the intersection point of the polygon edge with the
clipping edge and add it to the list of clipped vertices.
d. Continue this process for all edges of the clipping window.
e. The resulting list of clipped vertices forms the visible portion of the polygon within the
clipping window.
2. Weiler-Atherton Polygon Clipping Algorithm:
The Weiler-Atherton algorithm clips two polygons against each other. It can handle concave
and complex polygons and determine the clipped regions for both polygons. Here are the
main steps:
Page 10 of 11

a. Initialize two lists to store the vertices of the resulting clipped polygons.
b. Traverse both polygons, marking intersections between edges and recording their
coordinates.
c. Sort the intersection points by their x-coordinate to create a chain of intersection points.
d. Follow the chain of intersection points, connecting them to form clipped polygons.
e. Repeat this process for both polygons, ensuring that you correctly handle entry and exit
points at intersections.

The Weiler-Atherton algorithm is more versatile than the Sutherland-Hodgman algorithm but
requires careful handling of intersections between polygons. It can be used for polygon clipping in
various scenarios, including in computer-aided design (CAD) and computer graphics.

Window to Viewport transformation:


Window-to-viewport transformation, also known as the "viewing transformation" or "viewport
mapping," is a fundamental concept in computer graphics. It involves mapping coordinates from a
specified window (also known as the world or modeling coordinates) to the coordinates of a
viewport (the screen or display coordinates). This transformation is necessary to display the contents
of a scene or graphics in a specific region of the screen.

The transformation can be described using the following steps:

1. Define the Window and Viewport:


 The window defines a region in a world or modeling coordinate system where the
graphics or objects are located. It may have arbitrary dimensions and coordinates.
 The viewport represents the region on the screen where the graphics should be
displayed. It is usually defined by its screen coordinates and dimensions.
2. Establish a Coordinate System:
 Both the window and the viewport have their own coordinate systems.
 The window typically uses normalized coordinates, where (0,0) often corresponds to
the lower-left corner of the window, and (1,1) corresponds to the upper-right corner.
These normalized coordinates are device-independent and allow for easy scaling
when changing the window size.
3. Perform the Transformation:
 The window-to-viewport transformation maps points from the window's coordinate
system to the viewport's coordinate system.
 To map a point (Xw, Yw) from the window to the viewport, you can use the following
transformation:
Page 11 of 11

scssCopy code
Xv = Xw_min + (Xw - Xw_min) * (Xv_max - Xv_min) / (Xw_max - Xw_min) Yv = Yw_min + (Yw -
Yw_min) * (Yv_max - Yv_min) / (Yw_max - Yw_min)
where:
 (Xw, Yw) are the coordinates in the window.
 (Xv, Yv) are the coordinates in the viewport.
 (Xw_min, Yw_min) and (Xw_max, Yw_max) are the window's minimum and maximum
coordinates.
 (Xv_min, Yv_min) and (Xv_max, Yv_max) are the viewport's minimum and maximum
coordinates.
4. Draw or Render the Graphics:
 The transformed points in viewport coordinates are then used for rendering or
drawing graphics on the screen. Any objects or graphics originally defined in the
window coordinates are adjusted and displayed in the viewport.

The window-to-viewport transformation allows for rendering graphics or scenes regardless of their
original coordinates in a specific region of the screen. It's a key aspect of computer graphics systems,
enabling the display of objects with different sizes and locations on a computer screen or display.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy