UNIT 2 Notes
UNIT 2 Notes
Syllabus
Unit – II (12 hours)
Two Dimensional Viewing: Window-to- View Port Coordinate Transformation.
Line Clipping (Cohen-Sutherland Algorithm) and Polygon Clipping (Sutherland-
Hodgeman Algorithm) Aliasing and Antialiasing, Half Toning, Thresholding,
Dithering. Polygon Filling: Seed Fill Algorithm, Scan line Algorithm. Two
Dimensional Object Representations: Spline Representation, Bezier Curves, B-
Spline Curves. Fractal Geometry: Fractal Classification and Fractal Dimension..
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING, GIET (AUTONOMOUS), GUNUPUR
COMPUTER GRAPHICS - BCSPC7010 - 3-0-1 4
The following relation maintains the same relative placement of any point in the viewpoint and the
window:
[II.1]
COMPUTER GRAPHICS | Unit: 02
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING, GIET (AUTONOMOUS), GUNUPUR
COMPUTER GRAPHICS - BCSPC7010 - 3-0-1 4
Therefore
CLIPPING
Introduction:
Any procedure that identifies portions of the picture that are either inside or outside
of a specified region of space is referred to as a Clipping algorithm or Clipping.
Point Clipping:
A point clipping algorithm finds all the point that
are interior to a clipping window. Any point is said
to be interior to the clipping window, if it satisfies that
point visibility test
Line Clipping:
A line clipping is the process of
removing lines or portions of lines
outside of an area of interest.
Categorizing the lines:
i. The total line is visible.
ii. The total line is invisible.
iii. Segment of the line is visible.
COHEN-SUTHERLAND LINE CLIPPING ALGORITHM
The Cohen-Sutherland line clipping quickly detects & dispenses with two common and
trivial cases to clip a line. We need to consider only its end points.
[II.2]
COMPUTER GRAPHICS | Unit: 02
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING, GIET (AUTONOMOUS), GUNUPUR
COMPUTER GRAPHICS - BCSPC7010 - 3-0-1 4
Algorithm:
Step 1: Compute 4 bit outcodes for each endpoint.
Step 2: If both outcodes are 0000. [Bitwise ‘OR’ yields 0000]. The line is completely visible.
Step 3: If both outcodes have 1’s in the same bit position. [Bitwise ‘AND’ yields non 0000. Clip
the entire line. The line is completely invisible.
Step 4: The line may be partially visible or not visible. Calculate the intersection of the line with
appropriate windows edge.
Cohen-Sutherland Line Clipping Code
Cohen-Sutherland ( )
{
OutCode
Boolean accept=False, done=False;
do {
[II.3]
COMPUTER GRAPHICS | Unit: 02
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING, GIET (AUTONOMOUS), GUNUPUR
COMPUTER GRAPHICS - BCSPC7010 - 3-0-1 4
if (
{accept =True; done=Ture;} //Completely Visible
else if ) // bitwise AND
{ done=Ture;} // Completely Invisible
else { //Partially visible :Clipping
if (
else
if ( //TOP= 1000
{ Y=
else
}while (done=False);
if (accept =True)
{ line ( );}
}
Problem 01: Clip the line AB?
Solution: Code(A)=0101, Code(B)=0000;
Case I: Both Code(A), Code(B)= 0000 Completely Visible
But Code(A) 0000.
Case II: Find the same position 1’s in Code A and Code B.
So AB is completely invisible. But at same position
1’s are not available.
Case III: Partially visible.
The Point ‘A’ which intercept
X=
[II.4]
COMPUTER GRAPHICS | Unit: 02
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING, GIET (AUTONOMOUS), GUNUPUR
COMPUTER GRAPHICS - BCSPC7010 - 3-0-1 4
A’ = (10,8) Code(A’)=0100
B = (20,15) Code(B =0000;
Case I: A’B fully visible: Not accepted.
Case II: A’B fully invisible: Not Accepted.
Case III: the point A’ which intercept
B
Case I :
The line AB (5, 5, 20, 15) is clipped into (13,10,20,15).
POLYGON CLIPPING
A polygon is a closed figure bounded by straight lines with one bounded component and
one unbounded component. Computer graphics deals with both convex and concave polygons.
A convex polygon is such that no side extension cut any other side or vertex. It can be cut by
a straight line into two parts.
A polygon is
represented as a set
of vertices as
Convex Polygon with the
assumptions that
Concave Polygon is also an
edge.
A polygon is stored as a collection of vertices, any clipping algorithm takes one collection
and output new collection. A clipped polygon is also a polygon.
SUTHERLAND-HODGEMAN POLYGON CLIPPING
It is a simple and oldest polygon clipping algorithm. It is very efficient in two cases: one
being when the polygon is completely inside the boundaries and other when it is completely
outside. It uses a divide and conquer strategy to attack the problem. It first clip the polygon against
right clipping boundary. The result polygon is then clipped against the top, left and bottom clipping
boundary respectively.
[II.5]
COMPUTER GRAPHICS | Unit: 02
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING, GIET (AUTONOMOUS), GUNUPUR
COMPUTER GRAPHICS - BCSPC7010 - 3-0-1 4
Case I: if the previous vertex is outside the windows boundary and the current vertex is inside the
window boundary, then intersection point with the window edge and the current vertex are
added to the new vertex list.
Case II: if both the vertex are inside the window, the only the current vertex will be added to the
new vertex list.
Case III: if the previous vertex is inside the window boundary ad the current vertex is outside the
window boundary then only the intersection point with the window edge added to the new
vertex list.
Case IV: if both the vertices are outside the window boundary then the intersection points are tested
for visibility and then added to the vertex list else none.
To reconcile, Suherland-Hodegeman comprises of two key process the algorithm:
o Perform the inside-outside test to determine the visibility of a point or vertex:
o Determine the intersection of the polygon edge and the clipping plane.
ALIASING
Aliasing is a effect of displaying a high resolution image in a low resolution display.
The aliasing effect are also called artifact or distortion. The following effect may occur due
to aliasing:
a) Jagged Profile: it is especially noticed where there is a
high contrast between the interior and exterior of the
object.
b) Picket Fence Problem: it occurs when a user attempts
to scan convert an object that will not fit exactly in the
raster.
[II.6]
COMPUTER GRAPHICS | Unit: 02
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING, GIET (AUTONOMOUS), GUNUPUR
COMPUTER GRAPHICS - BCSPC7010 - 3-0-1 4
DITHERING:
[II.7]
COMPUTER GRAPHICS | Unit: 02
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING, GIET (AUTONOMOUS), GUNUPUR
COMPUTER GRAPHICS - BCSPC7010 - 3-0-1 4
Dithering is the process by which we create illusion of a color that are not present actually.
It is done by random arrangement of pixel. It is digital Halftoning process to approximate a color
that can’t be display with a uniform dots of the display device.
Seed fill algorithm are future classified into two broad categories:
Boundary Fill : fill boundary defined regions.
Flood Fill : fill the interior defined regions.
Boundary Fill:
Boundary fill is an algorithm used to fill an area with a specified color until the
specified boundary color is encountered.
The algorithm works by starting in a specified i.e. seed, filling the point
with a specified fill color, if it is not a boundary and recursively continuing with the four or
eight closest neighbors.
}
FLOOD FILLING ALGORITHM:
It is similar to boundary fill where we change the color of neighbor from seed point
but not up to boundary. It is basically used to change the color from old color to new color
in a connected region. Normally 8-Way filling algorithm is used.
}}
SCAN LINE ALGORITHM:
[II.9]
COMPUTER GRAPHICS | Unit: 02
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING, GIET (AUTONOMOUS), GUNUPUR
COMPUTER GRAPHICS - BCSPC7010 - 3-0-1 4
This algorithm works by intersecting scanline with polygon edges and fills the polygon
between pairs of intersections. The following
steps depict how this algorithm works.
Step 1 − Find out the Ymin and Ymax from
the given polygon.
Step 2 − ScanLine intersects with each edge of
the polygon from Ymin to Ymax. Name each
intersection point of the polygon. As per the
figure shown above, they are named as p0, p1,
p2, p3.
Step 3 − Sort the intersection point in the increasing order of X coordinate i.e. (p0, p1), (p1, p2), and
(p2, p3).
Step 4 − Fill all those pair of coordinates that are inside polygons and ignore the alternate pairs.
[II.10]
COMPUTER GRAPHICS | Unit: 02
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING, GIET (AUTONOMOUS), GUNUPUR
COMPUTER GRAPHICS - BCSPC7010 - 3-0-1 4
at the point.
SPLINE CURVES:
A spline curve is a mathematical representation for which it is easy to build an
interface that will allow a user to design and control the space of complex curves and
surface. The general approach is that the user enters a sequence of points and curve is
constructed
whose space closely follows the sequence. The points are called Control Points. A curve
that actually passes through each control point is called an interpolating curve, a curve that
passes near to the control points but not necessarily through them, called as an
approximating curve.
Bezier Curves:
Bezier curve is discovered by the French engineer Pierre Bezier. These curves can be
generated under the control of other points. Approximate tangents by using control point are used to
generate curve. The Bezier curve can be represented mathematically as
PROBLEM:
Construct the Bezier curve for following control points P0(4,2) ,P1(8,8) and P2(16,4).
ANSWER:
No of control point = 3 (n+1)
Where n is order = 3-1= 2
+
Expand in X, Y
[II.11]
COMPUTER GRAPHICS | Unit: 02
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING, GIET (AUTONOMOUS), GUNUPUR
COMPUTER GRAPHICS - BCSPC7010 - 3-0-1 4
U X(U) Y(U)
0 4 2
0.2 5.76 4
0.4 7.84 5.20
0.6 10.24 5.60
0.8 12.96 5.20
1.0 16 4
P
rope
rties
of
Bezi
er
Cur
ve
[II.12]
COMPUTER GRAPHICS | Unit: 02
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING, GIET (AUTONOMOUS), GUNUPUR
COMPUTER GRAPHICS - BCSPC7010 - 3-0-1 4
A given Bezier curve can be subdivided at a point t=t0 into two Bezier segments which join
together at the point corresponding to the parameter value t=t0.
B-Spline Curve
The Bezier curve produced by Bernstein basic function has limited flexibility.
The resulting polynomial is fixed by no of control point.
The Bezier curve is a global control.
The B-Spline basic contains the Bernstein basic as a special case. The B-Spline basic is
non-global.
A B-Spline curve is defined as a linear combination of control point and B-Spline basic
function given by
Where
is the order of polynomial segments means the curve is made up of piecewise
polynomial segments of degree K-1.
Normalized B-Spline blending function.
[II.13]
COMPUTER GRAPHICS | Unit: 02