2nd Unit - CG
2nd Unit - CG
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.
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 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
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:
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.
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.
Here's an overview of the window, viewport, and different types of clipping processes:
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:
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
Here are the key steps of the Cohen-Sutherland line clipping algorithm:
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.
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:
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.
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.