100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Class notes

Computer graphics-Unit-II RASTER SCAN GRAPHICS

Rating
-
Sold
-
Pages
32
Uploaded on
30-03-2023
Written in
2021/2022

chapter name :-RASTER SCAN GRAPHICS

Institution
Course











Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Course

Document information

Uploaded on
March 30, 2023
Number of pages
32
Written in
2021/2022
Type
Class notes
Professor(s)
S.gaikwad
Contains
Chapter 2

Subjects

Content preview

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
$8.59
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
shreyasshirsath

Get to know the seller

Seller avatar
shreyasshirsath silver lotus school
Follow You need to be logged in order to follow users or courses
Sold
0
Member since
2 year
Number of followers
0
Documents
14
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions