Unit 2 - Computer Graphics & Multimedia - WWW - Rgpvnotes.in
Unit 2 - Computer Graphics & Multimedia - WWW - Rgpvnotes.in
Unit 2 - Computer Graphics & Multimedia - WWW - Rgpvnotes.in
Tech
Subject Name: Computer Graphics & Multimedia
Subject Code: IT-601
Semester: 6th
Downloaded from www.rgpvnotes.in
Subject Notes
Unit II
Scan conversion techniques, image representation, line drawing, simple DDA, Bresenham’s Algorithm, Circle
drawing, general method, symmetric DDA, Bresenham’s Algorithm, curves, parametric function, Bezier
Method, B-spline Method.
Line drawing
The process of 'turning on' the pixels for a line segment is called vector generation. In this section, we study
the vector generation algorithm, Bresenham's line algorithm and circle drawing algorithms. Before discussing
specific line drawing algorithms, it is useful to note the general requirements for such algorithms. These
requirements specify the desired characteristics of line.
Characteristics of a line:
The line should be appearing as a straight line and it should start and end accurately.
The line should be displayed with constant brightness along its length independent of its length and
orientation.
The line should be drawn rapidly.
The basic concept behind all drawing algorithms is to reduce the computations and provide the result rapidly,
so most of the line drawing algorithms use incremental methods. In these methods line starts with starting
point and then a fix increment is added to get the next point on the line. This is continued till the end of line.
Consider first a line with positive slope, less than or equal to 1, we sample at unit intervals (∆x=1) and
compute each successive y value as yk+1 = yk + m, subscript k takes integer values starting from 1, for the first
point, and increases by 1 until the final endpoints is reached. Since m can be any real number between 0 & 1,
the calculated y values must be rounded to the nearest integer. For lines with a positive slope greater than 1,
we reserve the roles of x & y. That is, we sample at unit y intervals (∆y=1) and calculate each succeeding x
value as xk+1 = xk + (1/m).
13
12
11
10
6 7 8 9 10 11 12 13
DDA (digital differential analyzer) creates good lines but it is too time consuming due to the round function
and long operations on real values.
Key points:
DDA works with floating point arithmetic
Rounding to integers necessary
It takes lot of computation time because at each and every step it has to round off.
Advantages of DDA Algorithm
1. It is the simplest algorithm
Symmetrical DDA:
The Digital Differential Analyzer (DDA) generates lines from their differential equations. The equation of a
straight line is
The DDA works on the principle that we simultaneously increment x and y by small steps proportional to the
first derivatives of x and y. In this case of a straight line, the first derivatives are constant and are proportional
to ∆x and ∆y. Therefore, we could generate a line by incrementing x and y by ϵ ∆x and ϵ ∆y, where ϵ is some
small quantity. There are two ways to generate points
1. By rounding to the nearest integer after each incremental step, after rounding we display dots at the
resultant x and y.
2. An alternative to rounding the use of arithmetic overflow: x and y are kept in registers that have two parts,
integer and fractional. The incrementing values, which are both less than unity, are repeatedly added to the
fractional parts and whenever the results overflows, the corresponding integer part is incremented. The
integer parts of the x and y registers are used in plotting the line. In the case of the symmetrical DDA, we
choose ε=2-n, where 2n-1≤max (|∆x|, |∆y|) <2π
if pi ≥ 0
set the next pixel at position (xi +1, yi + 1 )
calculate new pi+1 = pi + 2y - 2x
Repeat steps until dx-1 times.
,
and use this equation to compute the pixels of the circle.
2. DDA Circle Drawing Algorithm We know that, the equation of circle, with origin as the center of the circle is
given as x2 + y2 = r2The digital differential analyser algorithm can be used to draw the circle by defining circle
as a differential equation. It is as given below,
Algorithm
1. Read the radius (R), of the circle and calculate value of epsilon
2. start_x = 0
start_y = R
3. X1 = start_x
Y1= start_y
4. do {
X2=X1 + epsilon*Y1
Y2 = Y1 + epsilon*X2
Plot (int ( X2 ), int ( Y2 ))
X1 = X2 ;
Y1 = Y2 ;
} while ( Y1— start_y ) < epsilon OR (start_x — X1 ) > epsilon)
[check if the current point is the starting point or not if current point is not starting point repeat step 4
; otherwise stop]
5. Stop.
As Circles are symmetrical so the values of y-intercept and x-intercept are same if circle's Center coordinates
are at Origin (0,0).
Curves:
In mathematics, a curve is an object similar to a line which does not have to be straight.
Parametric function:
Parameters for curve attributes are the same as those for line segments. We can display curves with varying
colours, widths, dot dash patterns, and available pen or brush options. Raster curves of various widths can be
displayed using the method of horizontal or vertical pixel spans. Where the magnitude of the curve slope is
less than 1, we plot vertical spans; where the slope magnitude is greater than 1, we plot horizontal spans.
Another method for displaying thick curves is to fill in the area between two parallel curve paths, whose
separation distance is equal to the desired width.
We could do this using the specified curve path as one boundary and setting up the second boundary either
inside or outside the original curve path. This approach shifts the original curve path either inward or outward,
depending on which direction we choose for the second boundary. We can maintain the original curve
position by setting the two boundary curves at a distance of one-half the width on either side of the specified
curve path. Although this method is accurate for generating thick circles, it provides only an approximation to
the true area of other thick curves. Curves drawn with pen and brush shapes can be displayed in different sizes
and with superimposed patterns or simulated brush strokes.
Parametric equations can be used to generate curves that are more general than explicit equations of the
form y=f(x). A quadratic parametric spline may be written as
P=a2t2+a1t+a0
where P is a point on the curve, a0, a1 and a2 are three vectors defining the curve and t is the parameter. The
curve passes through three points labelled P 0, P1 and P2. By convention the curve starts from point P 0 with
parameter value t=0, goes through point P1 when t=t1 (0<t1<1) and finishes at P2 when t=1. Using these
conventions, we can solve for the three a vector as follows:
Bezier Method:
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 points are used to generate curve. The Bezier
curve can be represented mathematically as –
Suppose we are given n+1 control point position:Pk = (Xk, Yk,Zk), with k = o to n. These coordinate points are
blended to produce the position vector P(u), which describes the path of an approximating Bezier Polynomial
Function between Po and Pn.
𝑛
𝑃(𝑢) = ∑𝑘=0 Pk BEZk, n(u) 0<=u<=1
The Bezier blending functions BEZk,n(u) are the Bernstein polynomials.
BEZk,n(u) = C(n,k)uk(1-u)n-k
Where,
C(n,k) are the binomial coefficients.
The simplest Bézier curve is the straight line from the point P0P0 to P1P1. A quadratic Bezier curve is
determined by three control points. A cubic Bezier curve is determined by four control points.
Where,
{pi: i=0, 1, 2….n} are the control points
ti: i = 0, . . . n + K
and if k > 1,
And