0% found this document useful (0 votes)
10 views18 pages

CG.unit 2

The document discusses various transformations in computer graphics, including basic transformations, homogeneous coordinates, and composite transformations. It covers specific types of transformations such as translation, scaling, rotation, reflection, and shearing, along with their mathematical representations and applications. Additionally, it explains windowing and clipping techniques, particularly the Cohen-Sutherland line clipping algorithm for managing visible portions of graphics within a defined viewing area.
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)
10 views18 pages

CG.unit 2

The document discusses various transformations in computer graphics, including basic transformations, homogeneous coordinates, and composite transformations. It covers specific types of transformations such as translation, scaling, rotation, reflection, and shearing, along with their mathematical representations and applications. Additionally, it explains windowing and clipping techniques, particularly the Cohen-Sutherland line clipping algorithm for managing visible portions of graphics within a defined viewing area.
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/ 18

Unit-II

Transformation: Basic transformation, matrix representations and homogeneous co-ordinates,


composite transformations, reflections and shearing, windowing clipping: Viewing pipeline,
viewing transformation, 2-D clipping algorithms- line clipping algorithms such as cohen
Sutherland line clipping algorithm.
1. Transformation: Basic transformation
Computer Graphics provide the facility of viewing object from different angles. The architect
can study building from different angles i.e.

1. Front Evaluation
2. Side elevation
3. Top plan

A Cartographer can change the size of charts and topographical maps. So, if graphics images
are coded as numbers, the numbers can be stored in memory. These numbers are modified by
mathematical operations called as Transformation.

The purpose of using computers for drawing is to provide facility to user to view the object
from different angles, enlarging or reducing the scale or shape of object called as
Transformation.

Two essential aspects of transformation are given below:

1. Each transformation is a single entity. It can be denoted by a unique name or symbol.


2. It is possible to combine two transformations, after connecting a single transformation
is obtained, e.g., A is a transformation for translation. The B transformation performs
scaling. The combination of two is C=AB. So C is obtained by concatenation
property.

There are two complementary points of view for describing object transformation.

1. Geometric Transformation: The object itself is transformed relative to the coordinate


system or background. The mathematical statement of this viewpoint is defined by
geometric transformations applied to each point of the object.
2. Coordinate Transformation: The object is held stationary while the coordinate system
is transformed relative to the object. This effect is attained through the application of
coordinate transformations.

An example that helps to distinguish these two viewpoints:

The movement of an automobile against a scenic background we can simulate this by

o Moving the automobile while keeping the background fixed-(Geometric


Transformation)
o We can keep the car fixed while moving the background scenery- (Coordinate
Transformation)

Homogeneous Co-ordinates
Homogeneous coordinates are a system used in projective geometry that allows for the
representation of points at infinity and simplifies mathematical transformations like
translation, rotation, and scaling.

In a 2D coordinate system, a point (x,y) can be represented in homogeneous coordinates as


(x,y,w) where w≠0w.The relationship between Cartesian and homogeneous coordinates is:

x’= x/w, y’= y/w

For example:

 The point (3,4) in Cartesian coordinates can be written as (3,4,1) in homogeneous


coordinates.
 If we scale this representation, (6,8,2) still represents the same Cartesian point (3,4)
since x′=6/2=3x' = 6/2 = 3x′=6/2=3 and y′=8/2=4y' = 8/2 = 4y′=8/2=4.

Why Use Homogeneous Coordinates?

(i) Simplifies Transformations: Translation, rotation, scaling, and perspective


projections can be represented using matrix multiplication.
(ii) Represents Points at Infinity: When w=0w = 0w=0, the point represents a point at
infinity, useful in perspective projections.
(iii) Unifies Geometric Operations: Different transformations can be combined
into a single matrix operation.

Homogeneous coordinates are widely used in computer graphics, robotics, and computer
vision for efficient transformations and 3D rendering.

Types of Transformations:

1. Translation
2. Scaling
3. Rotating
4. Reflection
5. Shearing

Translation
It is the straight line movement of an object from one position to another is called
Translation. 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 (x 1 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).

Matrix for Translation:

Scaling:
It is used to alter or change the size of objects. The change is done using scaling factors. There
are two scaling factors, i.e. S x in x direction Sy in y-direction. If the original position is x and y.
Scaling factors are Sx and Sy then the value of coordinates after scaling will be x1 and y1.

If the picture to be enlarged to twice its original size then S x = Sy =2. If Sxand Sy are not equal then
scaling will occur but it will elongate or distort the picture.

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.

Enlargement: If T1= ,If (x1 y1)is original position and T1is translation vector then (x2 y2)
are coordinated after scaling

The image will be enlarged two times

Reduction: If T1= . If (x1 y1) is original position and T1 is translation vector, then
(x2 y2) are coordinates after scaling
Matrix for Scaling:
Example: Prove that 2D Scaling transformations are commutative i.e, S1 S2=S2 S1.

Solution: S1 and S2 are scaling matrices

Rotation:

Rotation
In rotation, we rotate the object at particular angle θ (theta) from its origin.
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’).
Using standard trigonometric the original coordinate of point P(X, Y) can be
represented as −

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

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

Same way we can represent the point P’ (X’, Y’) as −

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θ

The rotation angle can be positive and negative.

For positive rotation angle, we can use the above rotation matrix. However,
for negative angle rotation, the matrix will change as shown below −

R=[cos(−θ)sin(−θ)−sin(−θ)cos(−θ)]

(∵cos(−θ)=cosθ, sin(−θ)=−sinθ)
Backward Skip 10sPla |

Composite Transformations omposition of two scaling is multiplicative. Let S11 and S12are

A number of transformations or sequence of transformations can be combined into single one


called as composition. The resulting matrix is called as composite matrix. The process of
combining is called as concatenation.

Suppose we want to perform rotation about an arbitrary point, then we can perform it by the
sequence of three transformations

1. Translation
2. Rotation
3. Reverse Translation

The ordering sequence of these numbers of transformations must not be changed. If a matrix is
represented in column form, then the composite transformation is performed by multiplying
matrix in order from right to left side. The output obtained from the previous matrix is multiplied
with the new coming matrix.

Example showing composite transformations:

The enlargement is with respect to center. For this following sequence of transformations will be
performed and all will be combined to a single one

Step1: The object is kept at its position as in fig (a)


Step2: The object is translated so that its center coincides with the origin as in fig (b)

Step3: Scaling of an object by keeping the object at origin is done in fig (c)

Step4: Again translation is done. This second translation is called a reverse translation. It will
position the object at the origin location.

Above transformation can be represented as TV.STV-1

Note: Two types of rotations are used for representing matrices one is column
method. Another is the row method.
Composition of two translations:

Let t1 t2 t3 t4are translation vectors. They are two translations P 1 and P2. The matrix of P1 and
P2 given below. The P1 and P2are represented using Homogeneous matrices and P will be the final
transformation matrix obtained after multiplication.

Above resultant matrix show that two successive translations are additive.

Composition of two Rotations: Two Rotations are also additive

Composition of two Scaling: The composition of two scaling is multiplicative.


Let S11 and S12are matrix to be multiplied.

Next / \
Reflection
Reflection In 2D Graphics

Reflection deals with obtaining a mirror image of the 2D object.


About x-axis:
If P(x, y) is the point on x-y plane then P’(x’, y’) is the reflection about x-axis given as x’=x ; y’=-y

About y-axis :
If P(x, y) is the point on x-y plane then P’(x’, y’) is the reflection about y-axis given as x’=-x ; y’=y
Along origin :
If P(x, y) is the point on x-y plane then P’(x’, y’) is the reflection about origin given as x’=-x ; y’=-y

Shearing

Shearing

deals with changing the shape and size of the 2D object along x-axis and y-axis. It is similar
to sliding the layers in one direction to change the shape of the 2D object.It is an ideal
technique to change the shape of an existing object in a two dimensional plane. In a two
dimensional plane, the object size can be changed along X direction as well as Y direction.
Horizontal Shearing

In horizontal shearing, the x-coordinates of points change proportionally to their y-


coordinates. The transformation can be written as:

( x' y′ )=( 1, 0, shx, 1)( x/y)

Where shx is the shearing factor for the x-axis.

Vertical Shearing

In vertical shearing, the y-coordinates of points change proportionally to their x-


coordinates. The transformation can be expressed as:

( x' y′ )=( 1, shy, 0, 1)( x/y)

Where shy is the shearing factor for the y-axis.

Shearing Transformation Matrices

Horizontal Shear Matrix

The matrix for horizontal shearing is:

( 1, 0, shx, 1)

Vertical Shear Matrix

The matrix for vertical shearing is:

( 1, shy, 0, 1)

Properties of Shearing

1. Linear Transformation: Shearing is a linear transformation that preserves


lines but alters the angles between the lines.

2. Non-rigid Transformation: The shape of objects changes by shearing;


however, it does not preserve their original angles unlike scaling or rotating.

3. Area Preservation: The area of a shape is preserved under a shearing


transformation.

x-Shear :

In x shear, the y co-ordinates remain the same but the x co-ordinates changes. If
P(x, y) is the point then the new points will be P’(x’, y’) given as –
x’=x+Shx∗y; y’=y

Matrix Form:

[x’ y’]=[x y].[1 0; Shx 1]

y-Shear :
In y shear, the x co-ordinates remain the same but the y co-ordinates changes. If P(x, y) is
the point then the new points will be P’(x’, y’) given as –

x’=x; y’=y+Shy∗x x’=x; y’=y+Shy∗x

Matrix Form:

[x’y’]=[xy].[1 Shy; 0 1]
Windowing and Clipping

Windowing is a technique that involves defining a viewing region within the overall display
area. This defined region, often referred to as a window or viewport, acts as a frame through
which the user observes the rendered scene. Windowing allows for the selection and
rendering of specific portions of a larger scene, enabling focused visualization and enhanced
user experience. By isolating the relevant content, windowing enables improved clarity and
detail, especially when dealing with complex and crowded scenes.

Clipping
The primary use of clipping in computer graphics is to remove objects, lines,
or line segments that are outside the viewing pane. The viewing
transformation is insensitive to the position of points relative to the viewing
volume − especially those points behind the viewer − and it is necessary to
remove these points before generating the view.

Point Clipping

Clipping a point from a given window is very easy. Consider the following
figure, where the rectangle indicates the window. Point clipping tells us
whether the given point (X, Y) is within the given window or not; and decides
whether we will use the minimum and maximum coordinates of the window.

The X-coordinate of the given point is inside the window, if X lies in between
Wx1 ≤ X ≤ Wx2. Same way, Y coordinate of the given point is inside the
window, if Y lies in between Wy1 ≤ Y ≤ Wy2.

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.

Explore our latest online courses and learn new skills at your own pace.
Enroll and become a certified expert to boost your career.

Cohen-Sutherland Line Clippings

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 −

 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 intersection point and draw only
that portion of line that is inside region).

Algorithm

Part-1
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 ANDoperation 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.

Part-2

Stept-1 from left side of the window

x= xmin

m= (y2 -y1)/(x2-x1)

(y-y1 )/(x -x1 ) = (y-y1 )/(xmin – x1 )

(y-y1 )= m(xmin – x1 ) or y= y1+ m(xmin – x1 )

Step-2 from right side of the window

x= xmax

y= y1+ m(xmax – x1 )

Step-3 from top of the window

y=ymax

m= (y-y1 )/(x -x1 ) = (ymax-y1)/(x-x1)

x = x1+(ymax-y1)/m

Step-4 from bottom of the window

y=ymin

x = x1+(ymin-y1)/m

Step-5 Stop

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