CG.unit 2
CG.unit 2
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.
There are two complementary points of view for describing object 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.
For example:
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).
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
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.
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)
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θ
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
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.
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
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.
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.
Next / \
Reflection
Reflection In 2D Graphics
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
Vertical Shearing
( 1, 0, shx, 1)
( 1, shy, 0, 1)
Properties of Shearing
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:
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 –
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.
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.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.
Part-2
x= xmin
m= (y2 -y1)/(x2-x1)
x= xmax
y= y1+ m(xmax – x1 )
y=ymax
x = x1+(ymax-y1)/m
y=ymin
x = x1+(ymin-y1)/m
Step-5 Stop