CGM CH 2
CGM CH 2
Compiled By:
Biswaraj Baral
Pokhara University
Chapter-2
Scan Conversion Algorithms
●
In any 2-Dimensional plane, if we connect two points (x0, y0) and (x1, y1), we get
a line segment. But in the case of computer graphics, we can not directly join any
two coordinate points, for that, we should calculate intermediate points’
coordinates and put a pixel for each intermediate point.
●
Rasterization: Rasterization in computer graphics is the process of converting
vector graphics or 3D models into a raster image, which is a grid of pixels. The
goal of rasterization is to determine which pixels in the display should be
illuminated to represent the objects in the scene. This process is a crucial step in
rendering graphics for display on computer screens.
●
DDA (Digital Differential Analyzer) algorithm is a fundamental graphics algorithm
used for generating lines and curves on a computer screen. The primary purpose
of the DDA algorithm in computer graphics is to draw a straight line between two
specified points. It provides a simple and efficient method for line rasterization.
Digital Differential Analyzer(DDA)
●
Points: Plotted by converting co-ordinate position to appropriate
operations for the output device (e.g.: in CRT monitor, the electron
beam is turned on to illuminate the screen phosphor at the selected
location.)
●
Line: Plotted by calculating intermediate positions along the line path
between two specified endpoint positions. Screen locations are
referenced with integer values, so plotted positions may only
approximate actual line positions between two specified endpoints “the
jaggies”. E.g.: position (10.48,20.51) → (10,21).
Digital Differential Analyzer (DDA)
●
Scan-conversion line – algorithm based on
calculating either Dx or Dy.
●
Sample the line at unit intervals in one coordinate
Determine the corresponding integer values nearest
the line path in another co-ordinate
Line Scan Conversion
DDA Algorithm
●
It is a scan conversion line algorithm based on calculation either △x
or △y using equation
m=△y/△x.
●
We sample the line at unit interval in one direction (X if △x is
greater than △y otherwise in y direction) and determine the
corresponding integer values nearest the line path for the other
coordinate.
●
Advantages of DDA:
– It is simple to understand.
– It is faster method than direct use of line equation y=mx+c.
(Removes multiplication operation and only involve increments
operation of x or y direction)
– It requires no special skills for implementation
●
Disadvantages of DDA:
– A floating point addition is still needed in determining each
successive point which is time consuming.
– The accumulation of round off error in successive addition of the
floating point increments may cause the calculated pixel position
to drift away from the true line path for long line segment.
●
Q. Digitized the line with end points (0,0) and (4,5) using DDA.
●
Q. Digitized the line with end points (0,0) and (4,5) using DDA.
●
●
Q. Digitized the line with end points (3,7) and (8,3) using DDA.
●
Q. Digitized the line with end points (7,4) and (3,2). Starting from
(7,4) using DDA.
●
Q. Digitized the line with end points (7,4) and (3,2). Starting from
(7,4) using DDA.
●
Solution: Here slope = (2-4)/(3-7) = 1/2=0.5 <1
And the position is right to left
So, Xk+1=Xk-1 ; and Yk+1 = Yk - m
d1- d2={2*ΔyXk+2*Δy-2Δx*yk+Δx2b-Δx}/Δx
●
Define Decision parameter (Pk) at Kth step which is
Pk=Δx (d1- d2)
BLA for positive Slope and |m|>1
●
Let us assume that pixel (Xk, Yk ) ks already plotted assuming that the
sampling direction in along X-axis ie (X k,Yk+1) or (Xk+1,Yk+1)
●
For slope greater than one, Y is incremented and the value of X is
evaluated
●
Yk+1 =Yk + 1
●
Xk+1=Xk, If (d1<d2)
●
Xk+1=Xk+1, If (d1>d2)
Where
d1= x-Xk
d2 = Xk+1 – x
d1-d2 = 2x-2Xk – 1
●
Now equation of line is given by: Y=mX+c
Equation of line at point Q
Yk+1=mx+c
X={Yk+1 – c}/m
●
Now putting the value in d1-d2
d1-d2 = 2{(Yk+1 – c)/m} -2Xk-1
●
●
Q. Apply Bresenham’s algorithm to draw a line
from (20,15) and end point is (30,30)
●
Q. Apply Bresenham’s algorithm to draw a line
from (-3,0) and end point is (4,4)
BLA for -ve slope and |M|<=1
BLA for -ve slope and |M|>1
●
Advantages of BLA over DDA:
– In DDA algorithm each successive point is computed in floating
point, so it requires more time and more memory space. While in
BLA each successive point is calculated in integer value or
whole number. So it requires less time and less memory space.
– In DDA, since the calculated point value is floating point number,
it should be rounded at the end of calculation but in BLA it does
not need to round, so there is no accumulation of rounding error.
– Due to rounding error, the line drawn by DDA algorithm is not
accurate, while in BLA line is accurate.
– DDA algorithm cannot be used in other application except line
drawing, but BLA can be implemented in other application such
as circle, ellipse and other curves.
Circle Algorithm
●
Circle is a set of all points that lie at
an equal distance from a fixed point
called centre.
●
Similarly to the case with lines,
there is an incremental algorithm for
drawing circles – the mid-point
circle algorithm
●
In the mid-point circle algorithm
we use eight-way symmetry so
only ever calculate the points for
the top right eighth (one octant)
of a circle, and then use symmetry
to get the rest of the points
●
Equation of circle : (x-h)2+(y-k)2=r2; center (h,k); radius (r)
Mid-Point Circle Algorithm: clockwise
Here, the mid-point (m) between (xk+1, yk) &(xk+1, yk-1)
=(xk+1, yk-1/2).
Now the decision parameter (Pk) is the circle function evaluated at
mid-point
Pk=fcircle(xk+1, yk-1/2) = (xk+1)2 + (yk-1/2)2 – r2
Stop at (7,7) because we have to calculate until x<=y; we have to find from 90
degree to 45 degree; at 45 degree x=y