0% found this document useful (0 votes)
27 views22 pages

CG Unit 2 Ashish

The document outlines the fundamental concepts of 2D geometrical transformations in computer graphics, including translation, scaling, rotation, shear, and reflection. It explains how these transformations manipulate objects in a two-dimensional space through coordinate systems and composite transformations. Additionally, it covers viewing transformations, clipping algorithms, and the use of homogeneous coordinates for efficient processing.

Uploaded by

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

CG Unit 2 Ashish

The document outlines the fundamental concepts of 2D geometrical transformations in computer graphics, including translation, scaling, rotation, shear, and reflection. It explains how these transformations manipulate objects in a two-dimensional space through coordinate systems and composite transformations. Additionally, it covers viewing transformations, clipping algorithms, and the use of homogeneous coordinates for efficient processing.

Uploaded by

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

Prepared by: Ashish Tripathi St Andrews Institute of Technology & Management, Gurugram

SYLLABUS

2|Page Ashish Tripathi


2D Geometrical Transforms
Transformations are fundamental part of computer graphics. In order to
manipulate object in two dimensional space, we must apply various
transformation functions to object. This allows us to change the position, size,
and orientation of the objects. Transformations are used to position objects, to
shape objects, to change viewing positions, and even to change how something is
viewed.
There are two complementary points of view for describing object movement.
The first is that the object itself is moved relative to a stationary coordinate
system or background. The second point of view holds that the object is held
stationary while the coordinate system is moved relative to the object. This effect
is attained through the application of coordinate transformations. An example
involves the motion of an automobile against a scenic background. We can also
keep the automobile fixed while moving the backdrop scenery (a coordinate
transformation).
Geometric Transformations
An object in the plane is represented as a set of points (vertices). Let us impose a
coordinate system on a plane. An object Obj in the plane can be considered as a
set of points. Every object point P has coordinates (x, y), and so the object is the
sum total of all its coordinate points. If the object is moved to a new position, it
can be regarded as a new object Obj' , all of whose coordinate point P’ can be
obtained from the original points P by the application of a geometric
transformation.
Points in 2-dimensional space will be represented as column vectors: There are
following types of transformation:
• Translation
• Scaling
• Rotation
• Shear
• Reflection

3|Page Ashish Tripathi


Translation
A translation moves an object to a different position on the screen. You can
translate a point in 2D by adding translation coordinate (tx, ty) to the original
coordinate (X, Y) to get the new coordinate (X’, Y’).

From the above figure, you can write that:


X’ = X + tx
Y’ = Y + ty
The pair (tx, ty) is called the translation vector or shift vector. The above
equations can also be represented using the column vectors:

We can write it as: P’ = P + T

Rotation about the origin


In rotation, the object is rotated θ° (theta) about the origin. The convention is
that the direction of rotation is counter-clockwise if θ is a positive angle and
clockwise if θ is a negative angle.
From the following figure, we can see that the point P(X, Y) is located at angle Φ
from the horizontal X coordinate with distance r from the origin. Let us suppose
you want to rotate it at the angle θ. After rotating it to a new location, you will get
a new point P’ (X’, Y’).

4|Page Ashish Tripathi


5|Page Ashish Tripathi
Scaling with Respect to the origin
Scaling is the process of expanding or compressing the dimension of an object.
Positive scaling constants Sx and Sy , are used to describe changes in length with
respect to the x direction and y direction, respectively. A scaling constant greater
than one indicates an expansion of length, and less than one, compression of
length. If both scaling constants have the same value s, the scaling
transformation is said to be homogeneous. Furthermore, if s > 1, it is a
magnification and for s < 1, a reduction.

6|Page Ashish Tripathi


Shear
A transformation that slants the shape of an object is called the shear
transformation. There are two shear transformations X-Shear and Y-Shear. One
shifts X coordinates values and other shifts Y coordinate values. However, in
both the cases, only one coordinate changes its coordinates and other preserves
its values. Shearing is also termed as Skewing.
X-Shear
The X-Shear preserves the Y coordinate and changes are made to X coordinates,
which causes the vertical lines to tilt right or left.

7|Page Ashish Tripathi


Reflection
Reflection is the mirror image of original object. In other words, we can say that
it is a rotation operation with 180˚. In reflection transformation, the size of the
object does not change. The following figures show reflections with respect to X
and Y axes, and about the origin respectively.

8|Page Ashish Tripathi


COMPOSITE TRANSFORMATION
If a transformation of the plane T1 is followed by a second plane transformation
T2, then the result itself may be represented by a single transformation T which
is the composition of T1 and T2 taken in that order. This is written as T = T1∙T2.
Composite transformation can be achieved by concatenation of transformation
matrices to obtain a combined transformation matrix.
A combined matrix: [T][X] = [X] [T1] [T2] [T3] [T4] …. [Tn]
Where [Ti] is any combination of
 Translation
 Scaling
 Shearing
 Rotation
 Reflection
The change in the order of transformation would lead to different results, as in
general matrix multiplication is not cumulative, that is [A] ∙ [B] ≠ [B] ∙ [A] and
the order of multiplication. The basic purpose of composing transformations is to
gain efficiency by applying a single composed transformation to a point, rather
than applying a series of transformation, one after another. For example, to
rotate an object about an arbitrary point (Xp, Yp), we have to carry out three
steps:
1. Translate point (Xp, Yp) to the origin.
2. Rotate it about the origin.
3. Finally, translate the center of rotation back where it belonged.

9|Page Ashish Tripathi


Example
Perform a 450 rotation of triangle A (0, 0), B (1, 1), C (5, 2)
(a) About the origin
(b) About point P (-1, -1)

(c)

10 | P a g e Ashish Tripathi
11 | P a g e Ashish Tripathi
Homogeneous Coordinate System
To perform a sequence of transformation such as translation followed by rotation
and scaling, we need to follow a sequential process:
1. Translate the coordinates,
2. Rotate the translated coordinates, and then
3. Scale the rotated coordinates to complete the composite transformation.
To shorten this process, we have to use 3×3 transformation matrix instead of 2×2
transformation matrix. To convert a 2×2 matrix to 3×3 matrix, we have to add an
extra dummy coordinate W. In this way, we can represent the point by 3
numbers instead of 2 numbers, which is called Homogenous Coordinate
system. In this system, we can represent all the transformation equations in
matrix multiplication. Any Cartesian point P(X, Y) can be converted to
homogenous coordinates by P’ (Xh, Yh, h).

12 | P a g e Ashish Tripathi
2-D VIEWING

A world-coordinate area selected for display is called a window. An area on a


display device to which a window is mapped is called a viewport. The window
defines what is to be viewed; the viewport defines where it is to be displayed.
Often, windows and viewports are rectangles in standard position, with the
rectangle edges parallel to the coordinate axes.
In general, the mapping of a part of a world-coordinate scene to device
coordinates is referred to as a viewing transformation. Sometimes the two-
dimensional viewing transformation is simply referred to as the window-to-
viewport transformation or the windowing transformation.

13 | P a g e Ashish Tripathi
The viewing coordinate reference frame is used to provide a method for setting
up arbitrary orientations for rectangular windows. Once the viewing reference
frame is established, we can transform descriptions in world coordinates to
viewing coordinates. We then define a Viewport in normalized coordinates (in
the range from O to I) and map the viewing-coordinate description of the scene
to normalized coordinates. At the final step, the parts of the picture that he
outside the viewport are clipped, and the contents of the viewport are transferred
to device coordinates.

Viewing Coordinate Reference Frame


First, a viewing-coordinate origin is selected at some world position: Po = (x0,
yo). Then we need to establish the orientation, or rotation, of this reference
frame. One way to do this is to specify a world vector V that defines the viewing
yv direction. Vector V is called the view up vector.
Given V, we can calculate the components of unit vectors v = (vx.vy) and u = (ux,
uy) for the viewing y, and x, axes, respectively. These unit vectors are used to
form the first and second rows of the rotation matrix R that aligns the viewing xv,
yv axes with the world xw, yw axes.

14 | P a g e Ashish Tripathi
A Window is a rectangular region in the world coordinate system. This is the
coordinate system used to locate an object in the natural world. The world
coordinate system does not depend on a display device, so the units of measure
can be positive, negative or decimal numbers.
A Viewport is the section of the screen where the images encompassed by the
window on the world coordinate system will be drawn. A coordinate
transformation is required to display the image, encompassed by the window, in
the viewport. The viewport uses the screen coordinate system so this
transformation is from the world coordinate system to the screen coordinate
system.
The final transformation matrix can be determined by composing the matrices
for the following transformations:
1. Translate the world-coordinate window to the origin.
2. Rotate the window to match the orientation of the screen window (i.e.
viewport).
3. Scale the window to match the size of the viewport.
4. Translate the window to the screen
When a window is "placed" on the world, only certain objects and parts of objects
can be seen. Points and lines which are outside the window are "cut off" from
view. This process of "cutting off" parts of the image of the world is called
Clipping.
In clipping, we examine each line to determine whether or not it is completely
inside the window, completely outside the window, or crosses a window
boundary. If inside the window, the line is displayed. If outside the window, the
lines and points are not displayed. If a line crosses the boundary, we must
determine the point of intersection and display only the part which lies inside the
window.
A window is specified by four world coordinates: wxmin, wxmax, wymin,and wymax
.Similarly, a viewport is described by four normalized device coordinates:
vxmin,vxmax,vymin, and vymax. The objective of window – to – viewport mapping is to
convert the world coordinates (wx, wy) of an arbitrary point to its corresponding
normalized device coordinates (vx,vy). In order to maintain the same relative
placement of the point in the viewport as in the window, we require:

15 | P a g e Ashish Tripathi
Cohen-

Point Clipping
Point clipping is essentially the evaluation of the following inequalities:
xmin ≤ x ≤ xmax and ymin ≤ y ≤ ymax
Where xmin, xmax, ymin and ymax define the clipping window. A point (x,y) is
considered inside the window when the inequalities all evaluate to true.

16 | P a g e Ashish Tripathi
Line Clipping
Lines that do not intersect the clipping window are either completely inside the
window or completely outside the window. On the other hand, a line that
intersects the clipping window is divided by the intersection point(s) into
segments that are either inside or outside the window.

Cohen - Sutherland Line Clipping


The Cohen-Sutherland line clipping algorithm quickly detects and dispenses with
two common and trivial cases. To clip a line, we need to consider only its
endpoints.
If both endpoints of a line lie inside the window, the entire line lies inside the
window. It is trivially accepted and needs no clipping. On the other hand, if both
endpoints of a line lie entirely to one side of the window, the line must lie entirely
outside of the window. It is trivially and needs to be neither clipped nor
displayed.
The algorithm employs an efficient procedure for finding the category of a line. It
proceeds in two steps:
1. Assign a 4-bit region code to each endpoint of the line. The code is determined
according to which of the following nine regions of the plane the endpoint lies in
Starting from the leftmost bit, each bit of the code is set to true (1) or false (0)
according to the scheme

17 | P a g e Ashish Tripathi
Bit 1 ≡ endpoint is above the window = sign (y – ymax)
Bit 2 ≡ endpoint is below the window = sign (ymin-y)
Bit 3 ≡ endpoint is to the right of the window = sign (x–xmax)
Bit 4 ≡ endpoint is to the left of the window = sign (xmin –x)
We use the convention that sign (a) = 1, if ‘a’ is positive, 0 otherwise. Of course, a
point with code 0000 is inside the window.
2. The line is visible if both region codes are 0000, and not visible if the bitwise
logical AND of the codes is not 0000, and a candidate for clipping if the bitwise
logical AND of the region codes is 0000.

For a line in category 3 we proceed to find the intersection point of the line with
one of the boundaries of the clipping window, or to be exact, with the infinite
extension of one of the boundaries. We choose an endpoint of the line, say (x1,
y1), that is outside the window, i.e., whose region code is not 0000. We then
select an extended boundary line by observing that those boundary lines that are
candidates for intersection are of ones for which the chosen endpoint must be
“pushed across” so as to change a “1” in its code to a “0” .
This means:
If bit 1 is 1, intersect with line y = ymax.
If bit 2 is 1, intersect with line y = ymin.
If bit 3 is 1, intersect with line x = xmax.

18 | P a g e Ashish Tripathi
If bit 4 is 1, intersect with line x = xmin.
Consider line CD. If endpoint C is chosen, then the bottom boundary line y=ymin
is selected for computing intersection. On the other hand, if endpoint D is
chosen, then either the top boundary line y=ymax or the right boundary line x =
xmax is used.
The coordinates of the intersection point are

Now we replace endpoint (x1, y1) with the intersection point (x1, yi) effectively
eliminating the portion of the original line that is on the outside of the selected
window boundary. The new endpoint is then assigned an updated region code
and the clipped line re-categorized and handled in the same way.

19 | P a g e Ashish Tripathi
20 | P a g e Ashish Tripathi
Area Clipping
An algorithm that clips a polygon is called an area clipping. Each edge of the
polygon must be tested against each edge of the clip rectangle; new edges must
be added, and existing edges must be discarded, retained, or divided.

21 | P a g e Ashish Tripathi
END OF UNIT II

22 | P a g e Ashish Tripathi

You might also like