0% found this document useful (0 votes)
50 views31 pages

2D Transformations in Computer Graphics

Uploaded by

maheswaranoop08
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)
50 views31 pages

2D Transformations in Computer Graphics

Uploaded by

maheswaranoop08
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

Computer Graphics MODULE 3

MODULE-3
2-D TRANSFORMATIONS

Transformation means changing some graphics into something else by applying rules. We can have
various types of transformations such as translation, scaling up or down, rotation, shearing, etc. When a
transformation takes place on a 2D plane, it is called 2D transformation.

Transformations play an important role in computer graphics to reposition the graphics on


the screen and change their size or orientation.

BASIC TRANSFORMATIONS:

(1)TRANSLATION:

It is the straight line movement of an object from one position to another is


calledTranslation. Here the object is positioned from one coordinate location to
another.
Translation of point:

To translate a point from coordinate position (x, y) to another (x1 y1), we add
algebraically the translation distances Tx and Ty to original coordinate.

x1=x+Tx
y1=y+Ty

The translation pair (Tx,Ty) is called as shift vector.


Translation is a movement of objects without deformation. Every position or point is
translated by the same amount. When the straight line is translated, then it will be drawn
using endpoints.
For translating polygon, each vertex of the polygon is converted to a new position. Similarly,
curved objects are translated. To change the position of the circle or ellipse its center
coordinates are transformed, then the object is drawn using new coordinates.

Let P is a point with coordinates (x, y). It will be translated as (x1 y1).

1
Computer Graphics MODULE 3

(2)ROTATION:

In rotation, we rotate the object at particular angle θ theta from its origin. From the following
figure, we can see that the point PX,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 willget a new point P’ X′,Y′

Using standard trigonometric the original coordinate of point P(X,Y) can be represented as

X=rcosϕ .....(1)

2
Computer Graphics MODULE 3

Y=rsinϕ ..... (2)

Same way we can represent the point P’ X′,Y′

x′=rcos(ϕ+θ)=rcosϕcosθ−rsinϕsinθ ...... (3)

y′=rsin(ϕ+θ)=rcosϕsinθ+rsinϕcosθ. ..... (4)

Substituting equation 1 & 2 in 3 & 4 respectively, we will get

x′=xcosθ−ysinθ

y′=xsinθ+ycosθ

Representing the above equation in matrix form,

Matrix for rotation

Matrix for homogeneous co-ordinate rotation

(3)SCALING:
To change the size of an object, scaling transformation is used. In the scaling process, you either
expandor compress the dimensions of the object. Scaling can be achieved by multiplying the original
coordinates of the object with the scaling factor to get the desired result.

Let us assume that the original coordinates are X,Y, the scaling factors are (S X, SY), and the produced

3
Computer Graphics MODULE 3

coordinates are X′,Y′. This can be mathematically represented as shown below −

X' = X . SX and Y' = Y . SY

The scaling factor SX, SY scales the object in X and Y direction respectively. The above equations can
also be represented in matrix form as below −

OR

P’ = P . S

Where S is the scaling matrix.

If scaling factors are less than one, then the size of the object will be reduced. If scaling
factors are higher than one, then the size of the object will be enlarged.

If Sxand Syare equal it is also called as Uniform Scaling. If not equal then called as
Differential Scaling. If scaling factors with values less than one will move the object closer
to coordinate origin, while a value higher than one will move coordinate position farther
from origin.

Matrix for Scaling:

4
Computer Graphics MODULE 3

Matrix Representation of 2D Transformation

5
Computer Graphics MODULE 3

HOMOGENOUS COORDINATES:

To perform a sequence of transformation such as translation followed by rotation and


scaling, we need to follow a sequential process −

• Translate the coordinates,

• Rotate the translated coordinates, and then

• 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 PX,YX,Y can be converted to
homogenous coordinates by P’ (Xh, Yh, h).

Example of representing coordinates into a homogeneous coordinate system: For two-


dimensional geometric transformation, we can choose homogeneous parameter h to any
non-zero value. For our convenience take it as one. Each two-dimensional position is then
represented with homogeneous coordinates (x, y, 1).

6
Computer Graphics MODULE 3

Following are matrix for two-dimensional transformation in


homogeneous coordinate:

7
Computer Graphics MODULE 3

EXTRA NOTES:

8
Computer Graphics MODULE 3

COMPOSITE TRANSFORMATIONS:

We can set up a matrix for any sequence of transformations as a composite transformation matrix by
calculating the matrix product of the individual transformations. Forming products of transformation
matrices is often referred to as a concatenation, concatenation, or composition, composition, of
matrices. For column-matrix representation of coordinate positions, we form composite
transformations by multiplying matrices in order from right to left. That is, each successive
transformation matrix pre multiplies the product of the preceding transformation matrices.

Translations

When two successive translations are applied to a point with translation vectors (tx1,ty1) and (tx2,ty2),
then

This demonstrates that successive translations are additive in nature.

Rotations

When two successive rotations are applied to a point ,

9
Computer Graphics MODULE 3

Scaling

When two successive scaling are applied to a point, with vectors (Sx1, Sy1) and (Sx2, Sy2)

This demonstrates that successive scalings are multiplicative in nature

Rotation with respect to a fixed reference point

We can generate rotations about any selected pivot point (xr, yr) by performing the following
sequence of translate- rotate-translate operations:
1. Translate the object so that the pivot-point position moved to the coordinate origin as shown in
fig (b).
2. Rotate the object about the origin as shown in fig (c).
3. Translate the object to its original position from origin. It is called as reverse translation as shown
in fig (d).

10
Computer Graphics MODULE 3

The matrix multiplication of above 3 steps is given below

Scaling relative to fixed point:

For this following steps are performed:

1. Translate the object so that the pivot-point position moved to the coordinate origin as shown in
fig (b).
2. Scaling of object by keeping object at origin is done as shown in fig (c)

3. Translate the object to its original position from origin. It is called as reverse translation as shown
in fig (d).

11
Computer Graphics MODULE 3

OTHER TRANSFORMATIONS

(1)Reflection:

It is a transformation which produces a mirror image of an object. The mirror image can be
either about x-axis or y-axis. The object is rotated by180°.

Types of Reflection:

1. Reflection about the x-axis


2. Reflection about the y-axis
3. Reflection about an axis perpendicular to xy plane and passing through the origin
4. Reflection about line y=x

1. Reflection about x-axis: The object can be reflected about x-axis with the help of the
following matrix

In this transformation value of x will remain same whereas the value of y will become
negative. Following figures shows the reflection of the object axis.
The object will lie another side of the x-axis.

12
Computer Graphics MODULE 3

2. Reflection about y-axis: The object can be reflected about y-axis with the help of
following transformation matrix

Here the values of x will be reversed, whereas the value of y will remain the same. The
object will lie another side of the y-axis.

The following figure shows the reflection about the y-axis

Reflection about an axis perpendicular to xy plane and passing through origin:


In the matrix of this transformation is given below

13
Computer Graphics MODULE 3

In this value of x and y both will be reversed. This is also called as half revolution about the origin.

3. Reflection about line y=x: The object may be reflected about line y = x with the
help of following transformation matrix

First of all, the object is rotated at 45°. The direction of rotation is clockwise. After it
14
Computer Graphics MODULE 3

reflection is done concerning x-axis. The last step is the rotation of y=x back to its
original position that is counterclockwise at 45°.
Example: A triangle ABC is given. The coordinates of A, B, C are given as A (3 4)
B (6 4)
C (4 8)

Find reflected position of triangle i.e., to the x-axis.

Solution:

The a point coordinates after reflection

15
Computer Graphics MODULE 3

The b point coordinates after reflection

The coordinate of point c after reflection

a (3, 4) becomes a1 (3, -4)


b (6, 4) becomes b1 (6, -4)
c (4, 8) becomes c1 (4, -8)

(2)Shearing:

It is transformation which changes the shape of object. The sliding of layers of object
occur. The shear can be in one direction or in two directions.

Shearing in the X-direction: In this horizontal shearing sliding of layers occur. The
homogeneous matrix for shearing in the x-direction is shown below:
x1=x+shx.y and y1=y

Shearing in the Y-direction: Here shearing is done by sliding along vertical or y-axis.

y1=y+shy.x and x1=x

16
Computer Graphics MODULE 3

2-DIMENSIONAL VIEWING:
THE VIEWING PIPELINE:
Basically, the window is an area in object space. It encloses the object. After the user selects this, space
is mapped on the whole area of the viewport. Almost all 2D and 3D graphics packages provide means of
defining viewport size on the screen. It is possible to determine many viewports on different areas of
display and view the same object in a different angle in each viewport.

Window: A world-coordinate area selected for display. The window defines what is to be viewed

Viewport : An area on a display device to which a window is mapped. The viewport defines
where it is to be displayed.

Windows and viewports are rectangles in standard position, with the rectangle edges parallel to
the coordinate axes.

Viewing transformation:
The mapping of a part of a world-coordinate scene to device coordinates.

2D viewing transformation is also called window-to- viewport transformation or the windowing


transformation.

17
Computer Graphics MODULE 3

First, we construct the scene in world coordinate using the output primitives and attributes.
18
Computer Graphics MODULE 3

To obtain a particular orientation, we can set up a 2-D viewing coordinate system in the window
coordinate plane and define a window in viewing coordinates system.

Once the viewing frame is established, are then transform description in world coordinates to viewing
[Link], we define viewport in normalized coordinates (range from 0 to 1) and map the viewing
coordinates description of the scene to normalized coordinates.

At the final step, all parts of the picture that (i.e., outside the viewport are dipped, and the contents are
transferred to device coordinates).

By changing the position of the viewport: We can view objects at different locations on the display
area of an output device as shown in fig:

By varying the size of viewports: We can change the size and proportions of displayed objects. We can
achieve zooming effects by successively mapping different-sized windows on a fixed-size viewport.

As the windows are made smaller, we zoom in on some part of a scene to view details that are not shown
with larger windows.

Window to Viewport Co-ordinate Transformation

Once object description has been transmitted to the viewing reference frame, we choose the window
extends in viewing coordinates and selects the viewport limits in normalized coordinates.

Object descriptions are then transferred to normalized device coordinates:

19
Computer Graphics MODULE 3

We do this thing using a transformation that maintains the same relative placement of an object in
normalized space as they had in viewing coordinates.

20
Computer Graphics MODULE 3

21
Computer Graphics MODULE 3

22
Computer Graphics MODULE 3

Line Clipping

The concept of line clipping is same as point clipping. In line clipping, we will cut the portion of line
which is outside of window and keep only the portion that is inside the window.
(1)Cohen-Sutherland Line Clipping Algorithm
This algorithm uses the clipping window as shown in the following figure. The minimum coordinate for
the clipping region is (XWmin,YWmin)(XWmin,YWmin) and the maximum coordinate for the clipping
region is (XWmax,YWmax)(XWmax,YWmax).

We will use 4-bits to divide the entire region. These 4 bits represent the Top, Bottom, Right, and Left of
the region as shown in the following figure. Here, the TOP and LEFT bit is set to 1 because it is the
TOP-LEFT corner.

There are 3 possibilities for the line −

23
Computer Graphics MODULE 3

● Line can be completely inside the window This line should be accepted .
● Line can be completely outside of the window This line will be completely removed from the
region
● Line can be partially inside the window We will find inter section point and draw only that
portion of line that is inside region
Algorithm
Step 1 − Assign a region code for each endpoints
Step 2 − If both endpoints have a region code 0000 then accept this line.
Step 3 − Else, perform the logical AND operation for both region codes.
Step 3.1 − If the result is not 0000, then reject the line.
Step 3.2 − Else you need clipping.
Step 3.2.1 − Choose an endpoint of the line that is outside the window.

Step 3.2.2 − Find the intersection point at the window boundary base on region code

Step 3.2.3 − Replace endpoint with the intersection point and update the region code.
Step 3.2.4 − Repeat step 2 until we find a clipped line either trivially accepted or trivially rejected.
Step 4 − Repeat step 1 for other lines.

Polygon Clipping

(1)Sutherland-Hodgeman Algorithm

A polygon can also be clipped by specifying the clipping window. Sutherland Hodgeman polygon
clipping algorithm is used for polygon clipping. In this algorithm, all the vertices of the polygon are
clipped against each edge of the clipping window.

First the polygon is clipped against the left edge of the polygon window to get new vertices of the
polygon. These new vertices are used to clip the polygon against right edge, top edge, bottom edge, of
the clipping window as shown in the following figure.

24
Computer Graphics MODULE 3

While processing an edge of a polygon with clipping window, an intersection point is found if edge is not
completely inside clipping window and the a partial edge from the intersection point to the outside edge
is clipped. The following figures show left, right, top and bottom edge clipping

There should be the following conditions while we clip a polygon.


Condition 1(Out-In): If the first vertex of the polygon is outside and the second vertex is inside the window,
then the output will be the intersection point and second vertex.

25
Computer Graphics MODULE 3

Condition 2(In-Out): If the first vertex of the polygon is inside and the second vertex is outside the window,
then the output will be the intersection point.

Condition 3(In-In): If both vertices of the polygon are inside the window, then the output will be the second
vertex.

Condition 4(Out-Out): If both vertices of the polygon are outside the window, then the output will be
nothing. It means we found a clipped polygon.

26
Computer Graphics MODULE 3

Text Clipping

Various techniques are used to provide text clipping in a computer graphics. It depends on
the methods used to generate characters and the requirements of a particular application. There are three
methods for text clipping which are listed below −

● All or none string clipping

● All or none character clipping

● Text clipping

The following figure shows all or none string clipping −

In all or none string clipping method, either we keep the entire string or we reject entire string based on
the clipping window. As shown in the above figure, STRING2 is entirely inside the clipping window so
we keep it and STRING1 being only partially inside the window, we reject.

The following figure shows all or none character clipping −

This clipping method is based on characters rather than entire string. In this method if the string is
entirely inside the clipping window, then we keep it. If it is partially outside the window, then −

● You reject only the portion of the string being outside

27
Computer Graphics MODULE 3

● If the character is on the boundary of the clipping window, then we discard that entire character
and keep the rest string.

The following figure shows text clipping −

This clipping method is based on characters rather than the entire string. In this method if the string is
entirely inside the clipping window, then we keep it. If it is partially outside the window, then

● You reject only the portion of string being outside.

● If the character is on the boundary of the clipping window, then we discard only that portion of
character that is outside of the clipping window.

28
Computer Graphics MODULE 3

29
Computer Graphics MODULE 3

30
Computer Graphics MODULE 3

31

Common questions

Powered by AI

Text clipping methods in computer graphics include: "All or None String Clipping," where entire strings are either fully displayed or rejected based on their presence within the clipping window, suited for applications needing complete textual units. "All or None Character Clipping," which applies acceptance based on individual character positioning relative to the window, useful for precise character inclusion. Lastly, "Text Clipping," involves keeping portions of characters that fall inside the window boundary, beneficial for scenarios requiring maximum visible text while omitting only outlying parts. Each method offers specific advantages based on text visibility requirements and computational constraints .

Line clipping in computer graphics involves determining and extracting the portion of a line that lies within a designated view window. The Cohen-Sutherland Line Clipping Algorithm is a widely used approach for this purpose. It defines a clipping window by its minimum and maximum coordinates and divides the entire space into regions using a 4-bit code representing positions relative to the window (Top, Bottom, Right, Left). For any line, the algorithm assigns region codes to its endpoints. If both endpoints have a code of 0000, the line is completely inside and accepted; if logical AND of both codes returns a non-zero result, the line is outside and rejected. Otherwise, if clipping is necessary, the algorithm calculates intersection points with window boundaries, updates the endpoints, and reiterates until the line is either trivially accepted or rejected. This method efficiently handles different line scenarios using bitwise operations .

Homogeneous coordinates involve representing two-dimensional points using three numbers (x, y, h), typically set as (x, y, 1) for convenience. This system is crucial for performing composite transformations, as it allows the use of 3x3 matrices instead of the standard 2x2 matrices. By utilizing homogeneous coordinates, we can perform multiple transformations (translation, rotation, scaling) in a sequence efficiently through matrix multiplication, thus simplifying the computational process and avoiding the need to apply each transformation separately .

In 2D transformations, uniform scaling occurs when the scaling factors (Sx, Sy) are equal, meaning the object's dimensions are expanded or contracted equally along both axes, maintaining the object's original proportions. Differential scaling, however, involves unequal scaling factors, resulting in the object being stretched or compressed disproportionately in the X and Y directions, thereby altering its original proportions. Uniform scaling retains the object's shape while altering its size, whereas differential scaling modifies both size and shape .

The viewport in a window to viewport transformation serves as the target display area on the output device where the object from the window coordinates is projected. By altering the position of the viewport, the location of the displayed object on the screen can be shifted. Changing the size or proportions of the viewport can resize the display of the object, creating zooming effects. Smaller viewports display detailed parts of a scene, whereas larger ones provide a broader view. These transformations maintain the same relative placement of objects in normalized space as they had in the viewing coordinates, enabling flexible visualization across different display settings .

To perform a rotation about an arbitrary pivot point (xr, yr) in 2D, the process involves three main steps: First, translate the object so that the pivot point corresponds to the origin. This is achieved by the translation matrix: T(−xr, −yr). Second, apply the rotation matrix to rotate the object with respect to the origin. Finally, translate the object back to its original position using the reverse translation matrix T(xr, yr). Mathematically, this sequence is expressed as RT = T(xr, yr) * R(θ) * T(−xr, −yr), where R(θ) is the rotation matrix, and T denotes translation. This chain of transformations ensures accurate rotation around a specified pivot .

Composite transformation matrices enable the concatenation of multiple transformations by providing a single matrix representation of several sequential operations (translation, rotation, scaling), calculated as the product of individual transformation matrices. Each subsequent matrix premultiplies the accumulated result of previous transformations, allowing for a streamlined application of complex sequences in a single matrix operation. This reduces computational complexity by avoiding repetitive transformation calculations, minimizes potential numerical errors, and ensures cohesive transformation application in graphics rendering .

Reflection in 2D transformations is a process to create a mirror image of an object. Key reflection types include reflection about the x-axis, achieved using the matrix [1 0; 0 -1], where x values remain unchanged and y values become negative. Reflection about the y-axis uses [−1 0; 0 1], reversing x values while keeping y values constant. Reflection about the line y=x employs a composite transformation: first, a 45° clockwise rotation, followed by a reflection about the x-axis, and lastly, a 45° counterclockwise rotation to restore orientation. These transformations alter object positioning symmetrically across the key axes or lines .

In 2D transformations, translation of a point involves moving the point from one coordinate to another. It is mathematically represented as x1 = x + Tx and y1 = y + Ty, where (Tx, Ty) is the translation vector. This reflects a linear transformation where each point is shifted by the same distance. On the other hand, rotation involves rotating the point around an origin by a certain angle θ. It is represented as x' = x cos θ - y sin θ and y' = x sin θ + y cos θ. Unlike translation, rotation changes the orientation of the object around a pivot point, typically the origin .

The Sutherland-Hodgeman polygon clipping algorithm processes each edge of a polygon sequentially against every edge of a clipping window. The algorithm involves four possible conditions: if both vertices of an edge are inside the window (In-In), only the second vertex is retained; if the first is inside, but the second is outside (In-Out), an intersection point is added; if the first is outside and the second inside (Out-In), both the intersection point and the second vertex are kept; if both vertices are outside (Out-Out), no output is generated. This systematic checking against all window edges effectively trims the polygon to fit within the given bounds, helping to achieve accurate rendering and minimizing unnecessary computations .

You might also like