Garantie de satisfaction à 100% Disponible immédiatement après paiement En ligne et en PDF Tu n'es attaché à rien 4.2 TrustPilot
logo-home
Notes de cours

Computer graphics-Unit-II RASTER SCAN GRAPHICS

Note
-
Vendu
-
Pages
32
Publié le
30-03-2023
Écrit en
2021/2022

chapter name :-RASTER SCAN GRAPHICS

Établissement
Cours











Oups ! Impossible de charger votre document. Réessayez ou contactez le support.

École, étude et sujet

Cours

Infos sur le Document

Publié le
30 mars 2023
Nombre de pages
32
Écrit en
2021/2022
Type
Notes de cours
Professeur(s)
S.gaikwad
Contient
Chapter 2

Sujets

Aperçu du contenu

Unit-II Raster Scan Graphics


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++)

CGR-22318 www.freestudyroom.xyz Page 3

, Unit-II Raster Scan Graphics
{
x=x+xinc;
y=y+yinc;
putpixel(x,y,WHITE);
delay(100);
}
getch();
closegraph();
return 0;
}
OUTPUT:




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
€7,53
Accéder à l'intégralité du document:

Garantie de satisfaction à 100%
Disponible immédiatement après paiement
En ligne et en PDF
Tu n'es attaché à rien

Faites connaissance avec le vendeur
Seller avatar
shreyasshirsath

Faites connaissance avec le vendeur

Seller avatar
shreyasshirsath silver lotus school
S'abonner Vous devez être connecté afin de suivre les étudiants ou les cours
Vendu
0
Membre depuis
2 année
Nombre de followers
0
Documents
14
Dernière vente
-

0,0

0 revues

5
0
4
0
3
0
2
0
1
0

Récemment consulté par vous

Pourquoi les étudiants choisissent Stuvia

Créé par d'autres étudiants, vérifié par les avis

Une qualité sur laquelle compter : rédigé par des étudiants qui ont réussi et évalué par d'autres qui ont utilisé ce document.

Le document ne convient pas ? Choisis un autre document

Aucun souci ! Tu peux sélectionner directement un autre document qui correspond mieux à ce que tu cherches.

Paye comme tu veux, apprends aussitôt

Aucun abonnement, aucun engagement. Paye selon tes habitudes par carte de crédit et télécharge ton document PDF instantanément.

Student with book image

“Acheté, téléchargé et réussi. C'est aussi simple que ça.”

Alisha Student

Foire aux questions