Unit 2
Unit 2
1151CS125-COMPUTER GRAPHICS
UNIT-2
https://youtu.be/15aqFQQVBWU
COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE
Raster Images
• Computer graphics can be created as either raster or vector images.
Raster graphics are bitmaps.
• A bitmap is a grid of individual pixels that collectively compose an
image.
• Raster graphics render images as a collection of countless tiny squares.
• Each square, or pixel, is coded in a specific hue or shade.
• Individually, these pixels are worthless. Together, they’re worth a
thousand words.
Types of Transformation
There are two types of transformation in computer graphics.
1) 2D transformation
2) 3D transformation
COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE
2D and 3D Transformations
Types of 2D and 3D transformation
1) Translation
2) Rotation
3) Scaling
4) Shearing
5) Mirror reflection
Object Transformation in 2D
Alter the coordinates descriptions an object
Translation , rotation , scaling , shearing, reflection.
Coordinate system unchanged
Coordinate transformation in 2D
Produce a different coordinate system
Let-
2D Translation
https://www.mathwar
ehouse.com/animate
d-gifs/transformations
.php#translations
Given a circle C with radius 10 and center coordinates (1, 4). Apply the translation with
distance 5 towards X axis and 1 towards Y axis. Obtain the new coordinates of C without
Solution-
Given-
Old center coordinates of C = (X old, Yold) = (1, 4)
Translation vector = (Tx, Ty) = (5, 1)
Let the new center coordinates of C = (X new, Ynew).
Applying the translation equations, we have-
Xnew = Xold + Tx = 1 + 5 = 6
Ynew = Yold + Ty = 4 + 1 = 5
Thus, New center coordinates of CGRAPHICS
COMPUTER = (6, 5).
-1151CS125 Dr.T.KAMALESHWAR AP/CSE
PRACTICE PROBLEMS BASED ON 2D TRANSLATION
In matrix form, the new center coordinates of C after translation may be
obtained as-
Let- https://www.math
warehouse.com/an
imated-gifs/transfo
Initial coordinates of the object O = (Xold, Yold) rmations.php#rota
tions
Initial angle of the object O with respect to origin = Φ
Rotation angle = θ
Given a line segment with starting point as (0, 0) and ending point as
(4, 4). Apply 30 degree rotation anticlockwise direction on the line segment and
Solution-
We rotate a straight line by its end points with the same angle. Then, we re-draw
a line between the new end points.
Given-
Let new ending coordinates of the line after rotation = (Xnew, Ynew).
COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE
PRACTICE PROBLEMS BASED ON 2D ROTATION
Applying the rotation equations, we have
Xnew = Xold x cosθ – Yold x sinθ
= 4 x cos30º – 4 x sin30º
= 4 x (√3 / 2) – 4 x (1 / 2)
= 2√3 – 2
= 2(√3 – 1)
= 2(1.73 – 1)
= 1.46
Ynew = Xold x sinθ + Yold x cosθ
= 4 x sin30º + 4 x cos30º
= 4 x (1 / 2) + 4 x (√3 / 2)
= 2 + 2√3
= 2(1 + √3) Thus, New ending coordinates of the line after
= 2(1 + 1.73) rotation = (1.46, 5.46).
= 5.46
COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE
PRACTICE PROBLEMS BASED ON 2D ROTATION
In matrix form, the new ending coordinates of the line after rotation may
be obtained as-
Thus, New ending coordinates of the line after rotation = (1.46, 5.46).
COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE
2D Scaling
Xnew = Xold x Sx
Ynew = Yold x Sy
Given a square object with coordinate points A(0, 3), B(3, 3), C(3, 0), D(0, 0).
Apply the scaling parameter 2 towards X axis and 3 towards Y axis and
obtain the new coordinates of the object.
Solution-
Given-
• Old corner coordinates of the square = A (0, 3), B(3, 3), C(3, 0), D(0, 0)
• Scaling factor along X axis = 2
Let-
= (Xnew, Ynew)
Given a triangle with coordinate points A(3, 4), B(6, 4), C(5, 6). Apply the reflection
on the X axis and obtain the new coordinates of the object.
Solution-
Given-
Old corner coordinates of the triangle = A (3, 4), B(6, 4), C(5, 6)
Reflection has to be taken on the X axis
For Coordinates A(3, 4)
Let the new coordinates of corner A after reflection = (Xnew, Ynew).
Applying the reflection equations, we have-
Xnew = Xold = 3
Ynew = -Yold = -4
Thus, New coordinates of corner A after reflection = (3, -4). Dr.T.KAMALESHWAR AP/CSE
COMPUTER GRAPHICS -1151CS125
PRACTICE PROBLEMS BASED ON 2D REFLECTION
1. Shearing in X direction
2. Shearing in Y direction
Consider a point object O has to be sheared in a 2D plane.
Let-
•Initial coordinates of the object O = (Xold, Yold)
Shearing in X Axis-
Ynew = Yold = 1
Applying the shearing equations, we have-
Ynew = Yold = 0
Thus, New coordinates of corner B after shearing = (0, 0).
Ynew = Yold = 0
Thus, New coordinates of the triangle after shearing in X axis = A (3, 1),
Shearing in Y Axis-
Xnew = Xold = 1
Xnew = Xold = 0
Xnew = Xold = 1
Shearing in X Axis-
Ynew = Yold = 1
Applying the shearing equations, we have-
Ynew = Yold = 0
Thus, New coordinates of corner B after shearing = (0, 0).
Ynew = Yold = 0
Thus, New coordinates of the triangle after shearing in X axis = A (3, 1),
Shearing in Y Axis-
Xnew = Xold = 1
Xnew = Xold = 0
Xnew = Xold = 1
Shearing in X Axis-
Ynew = Yold = 1
Applying the shearing equations, we have-
Ynew = Yold = 0
Thus, New coordinates of corner B after shearing = (0, 0).
Ynew = Yold = 0
Thus, New coordinates of the triangle after shearing in X axis = A (3, 1),
Shearing in Y Axis-
Xnew = Xold = 1
Xnew = Xold = 0
Xnew = Xold = 1
This algorithm uses the clipping window as shown in the below figure. The
minimum coordinate for the clipping region is (XWmin,YWmin) and the
maximum coordinate for the clipping region is (XWmax,YWmax)
We will find intersection point and draw only that portion of line that is
inside region
Example: Window size is (-3, 1) to (2, 6). A line AB is given having co-
ordinates of A (-4, 2) and B (-1, 7). Does this line visible. Find the visible
portion of the line using midpoint subdivision?
Solution:
• Step1: Fix point A (-4, 2)
X = x1 + t(x2-x1)
Y = y1 + t(y2-y1)
respectively).
When the line is parallel to a view window boundary, the p value for that
boundary is zero.
• When pk < 0, as t increase line goes from the outside to inside (entering).
view window.
• When pk = 0 and qk > 0 then the line is inside the corresponding window
boundary.
Using the following conditions, the position of line can be determined:
Condition Position of line
• Parameters t1 and t2 can be calculated that define the part of line that lies
within the clip rectangle.
When,
• If t1 > t2, the line is completely outside the clip window and it can be
rejected. Otherwise, the endpoints of the clipped line are calculated from
the two values of parameter t.
(-5+(20)·(3/4), 3+(6)·(3/4))
• Triangles
• Pentagons
• Hexagons
• Quadrilaterals
• The polygon’s name defines how many sides the architecture contains.
• Concave Polygon
• Convex Polygon
• Concave Polygon: The concave polygon does not have any part of its
diagonals in its exterior. In a concave polygon, at least one angle should be
exterior. In a convex polygon, all the angles should be less than 180°
(angle<180°).
Polygon Clipping
inside the view pane or window. We will remove or clip the part that is
outside the window. We will use the following algorithms for polygon
clipping-
• Sutherland-Hodgeman polygon clipping algorithm
• Weiler-Atherton polygon clipping algorithm
COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE
Sutherland Hodgeman Polygon Clipping
Explanation:
1. Finding all the intersection points and grouping them
Here, let there be a polygon ABCD and another polygon VWXYZ. Let
ABCD be the clipping polygon and let VWXYZ be the clipped polygon.
So, we can find the intersection points using any method. For example, we
can find the intersecting points separately and then find for each intersecting
point find if it is entering or leaving, or, we can use Cyrus Beck and find all
the intersecting points and also get if a point is entering or exiting. Refer
Cyrus Beck for more information on this algorithm.
• From here we begin the making of the list of vertices (or vector) to make a
clipped sub-polygon.
Limitations:
• This polygon clipping algorithm does not work for self – intersecting
polygons, although some methods have been proposed to be able to solve
this issue also, and have successfully worked.
In all or none string clipping method, either we keep the entire string or we reject
entire string based on the clipping window.
COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE
Text Clipping
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
REFERENCES
1. DaveShreiner, Graham Sellers, John M. Kessenich, Bill M. Licea-Kane ,”OpenGL
Programming Guide: The Official Guide to Learning OpenGL, Version 4.3”, 8th
Edition, ARB working group.
2. Hearn and Baker, “Computer Graphics using open GL”, 3rd edition, Pearson
Education,2009.
3. Rogers, “Procedural Element for Computer Graphics”, 2nd ed, Tata McGraw Hill,
2001.
4. Peter Shirley, Michael Ashikhmin, Michael Gleicher, Stephen R Marschner, Erik
Reinhard, KelvinSung, and AK Peters, Fundamental of Computer Graphics, CRC
Press, 2010.
5. William M. Newman and Robert F.Sproull, “Principles of Interactive Computer
Graphics”, Mc GrawHill 1978.