Second Year Diploma Courses in Computer Science & Engineering / Computer
Engineering / Computer Technology / Information Technology Branch.
Computer Graphics
As per MSBTE ‘I’ Scheme Syllabus
CGR-22318
Unit-II
RASTER SCAN GRAPHICS
Total Marks- 12
Contents:
2.1 Basic concepts in line drawing,:
2.1.1 Line.
2.1.2 Drawing algorithms:
1. Digital Differential Analyzer (DDA) algorithm,
2. Bresenham's algorithm.
2.2 Circle generating algorithms:
2.2.1 Symmetry of circle,
2.2.2 Bresenham’s circle drawing algorithm.
2.3 Polygons –
2.3.1 Types of polygons,
2.3.2 inside-outside test,
2.3.3 Polygon Filling:
A. Seed fill algorithms:
A.1 Flood fill.
A.2 Boundary fill,
B. scan line algorithms
2.4 Scan conversion,
2.5 Frame Buffers.
2.6 Character generation methods:
1. stroke,
2. starburst,
3. bitmap.
CGR-22318 www.freestudyroom.xyz Page 1
, Unit-II Raster Scan Graphics
Unit-II Raster Scan Graphics
2.1 Basic Concept in Line Drawing:
2.1.1 Line: Line is a straight object with no curves, no thickness and it extends in both
directions without end. If it does have ends it is called as a line segment.
The process is turning on pixels for a line segment is called vector generation or line
generation and algorithm for them is known as vector generation algorithm or line drawing
algorithm.
Problems of vector generation:
Line is straight but width is no constant.
Brightness of line dependent on orientation of the line.
Calculate only an approximate line length.
Reduce the calculations using simple integer arithmetic.
2.1.2 Line Drawing Algorithms:
Line drawing algorithms are classified as Digital Differential Analyzer (DDA) algorithm
and Bresenham’s algorithm.
1. DDA Algorithm (Digital Differential Analyzer)
DDA algorithm is an incremental scan conversion method. Here we perform calculations at
each step using the results from the previous step.
We know that the slop of a straight line is given as -
Slop(
Where
m=Slop of line
dy=distance of y co-ordinates
dx=distance of x co-ordinates
The above differential equation can be used to obtain a rasterized straight line. For any given
x interval x along a line, we can compute the corresponding y interval y.
Similarly, we can obtain the x interval x corresponding to a specified y.
Once the intervals are known the values for next x and next y on the straight line can be
obtained.
Digital Differential Analyzer (DDA) algorithm is the simple line generation algorithm which
is explained step by step here.
Vector generation/DDA Line Algorithm –
1. Read line end points(x1,y1) and (x2,y2) such that they are not equal.
(If equal then plot that point and exit)
2. Compute Horizontal and Vertical differences-
dy=|y2-y1| and dx=|x2-x1|
3. if (|dx|>=|dy) then
steps=dx
else
steps=dy
4. Increment x, xinc=dx/steps
CGR-22318 www.freestudyroom.xyz Page 2
, Unit-II Raster Scan Graphics
5. Increment y, yinc=dy/steps
6. x=x1+0.5*sign(dx)
y=y1+0.5*sign(dy)
(here, sign function makes the algorithm work in all quadrant.)
7. for(i=0;i<steps;i++)
{
Plot (Integer(x), Integer(y))
x1=x+xinc
y1=y+yinc
}
8. Stop
‘C’ Code for DDA Line Drawing Algorithm:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
int sign(float val)
{
if(val<0)
return -1;
else
return 1;
}
int main()
{
int gd=DETECT,gm,i;
float x,y,x1,y1,x2,y2,dx,dy,xinc,yinc,steps;
initgraph(&gd,&gm,"C:\\TurboC3\\BGI");
printf("Enter x1,y1");
scanf("%f%f",&x1,&y1);
printf("Enter x2,y2");
scanf("%f%f",&x2,&y2);
dx=abs(x2-x1);
dy=abs(y2-y1);
if(dx>=dy)
{
steps=dx;
}
else
{
steps=dy;
}
xinc=dx/steps;
yinc=dy/steps;
x=x1+0.5*sign(dx); (Initial value with adding the factor 0.5 to make round value for x,
also sign function work in all quadrant.)
y=y1+0.5*sign(dy); (Initial value with adding the factor 0.5 to make round value for
y, also sign function work in all quadrant.)
putpixel(x,y,WHITE);
for(i=1;i<=steps;i++)
Example 1: Consider the line from (0,0) to (4,6). Use the simple DDA algorithm to rasterize
this line.
Solution: Evaluating steps 1 to 5 in the DDA algorithm we have,
We have,
xl = 0, y1 = 0
x2 = 4, y2 = 6
dx=|x2 – x1| =4-0=4
dy =|y2 – yl|=6-0=6
here, dy is greater than dx
so, steps = dy = 6
Increment x, xinc=dx/steps=4/6=0.667
Increment y, yinc=dy/steps=6/6=1
Initial value with adding the factor 0.5 to make round value for x & y, also sign function work
in all quadrant.
x=0 + 0.5 sign (dx) = 0.5
y =0 + 0.5 sign (dy) = 0.5
Plot integer now:
1. Plot (0, 0), x=0.5, y=0.5
2. Plot (1, 1), x=x+ dx =0.5+0.667=1.167, y=y+ dy=0.5+1=1.5
3. Plot (1, 2), x=x+ dx =1.167+0.667=1.833 y=y+ dy =1.5+1=2.5
4. Plot (2, 3), x=x+ dx =1.833+0.667=2.5 y=y+ dy =2.5+1=3.5
5. Plot (3, 4), x=x+ dx =2.5+0.667=3.167 y=y+ dy =3.5+1=4.5
6. Plot (3, 5), x=x+ dx =3.167+0.667=3.833 y=y+ dy =4.5+1=5.5
7. Plot (4, 6) x=x+ dx =3.833+0.667=4.5 y=y+ dy =5.5+1=6.5
Tabulating the result of each iteration-
i x y plot
1 0.50 0.50 (0,0)
2 1.17 1.50 (1,1)
3 1.83 2.50 (1,2)
4 2.50 3.50 (2,3)
CGR-22318 www.freestudyroom.xyz Page 4
Les avantages d'acheter des résumés chez Stuvia:
Qualité garantie par les avis des clients
Les clients de Stuvia ont évalués plus de 700 000 résumés. C'est comme ça que vous savez que vous achetez les meilleurs documents.
L’achat facile et rapide
Vous pouvez payer rapidement avec iDeal, carte de crédit ou Stuvia-crédit pour les résumés. Il n'y a pas d'adhésion nécessaire.
Focus sur l’essentiel
Vos camarades écrivent eux-mêmes les notes d’étude, c’est pourquoi les documents sont toujours fiables et à jour. Cela garantit que vous arrivez rapidement au coeur du matériel.
Foire aux questions
Qu'est-ce que j'obtiens en achetant ce document ?
Vous obtenez un PDF, disponible immédiatement après votre achat. Le document acheté est accessible à tout moment, n'importe où et indéfiniment via votre profil.
Garantie de remboursement : comment ça marche ?
Notre garantie de satisfaction garantit que vous trouverez toujours un document d'étude qui vous convient. Vous remplissez un formulaire et notre équipe du service client s'occupe du reste.
Auprès de qui est-ce que j'achète ce résumé ?
Stuvia est une place de marché. Alors, vous n'achetez donc pas ce document chez nous, mais auprès du vendeur shreyasshirsath. Stuvia facilite les paiements au vendeur.
Est-ce que j'aurai un abonnement?
Non, vous n'achetez ce résumé que pour €8,15. Vous n'êtes lié à rien après votre achat.