You are on page 1of 4

COMPUTER GRAPHICS & MULTIMEDIA

(DCO-511)
Program no. 5

Program Name: Draw a line in graphics using DDA & Breshman Algorithms.

Submitted by:

Sharique Baig

Roll. No. 16-DCS-063

Diploma in Computer Engineering-5th Semester

Computer Engineering Section


University Polytechnic, Faculty of Engineering and Technology

Jamia Millia Islamia (A Central University)

New Delhi-110025
Session 2018-2019
PROGRAM( USING BRESHMAN ALGORITHM)
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
void main()
{
int gdriver=DETECT, gmode, error, x0, y0, x1, y1;
int dx, dy, p, x, y;
initgraph(&gdriver, &gmode, "c:\\turboc3\\bgi");
printf("Enter co-ordinates of first point: ");
scanf("%d%d", &x0, &y0);
printf("Enter co-ordinates of second point: ");
scanf("%d%d", &x1, &y1);
dx=x1-x0;
dy=y1-y0;
x=x0;
y=y0;
p=2*dy-dx;
while(x<x1){
if(p>=0){
putpixel(x,y,7);
y=y+1;
p=p+2*dy-2*dx;
}
else{
putpixel(x,y,7);
p=p+2*dy;
}
x=x+1;
}
getch();
}
OUTPUT
PROGRAM( USING DDA ALGORITHM)
#include<graphics.h>
#include<stdio.h>
#include<math.h>
#include<conio.h>
void main( )
{
float x,y,x1,y1,x2,y2,dx,dy,step;
int i,gd=DETECT,gm;
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
printf("Enter the value of x1 and y1 : ");
scanf("%f%f",&x1,&y1);
printf("Enter the value of x2 and y2: ");
scanf("%f%f",&x2,&y2);
dx=abs(x2-x1);
dy=abs(y2-y1);
if(dx>=dy)
step=dx;
else
step=dy;
dx=dx/step;
dy=dy/step;
x=x1;
y=y1;
i=1;
while(i<=step){
putpixel(x,y,5);
x=x+dx;
y=y+dy;
i=i+1;
}

closegraph();
getch();
}
Difference Between DDA Line Drawing Algorithm and
Bresenhams Line Drawing Algorithm.

Digital Differential Analyzer Bresenhams Line Drawing Algorithm


Line Drawing Algorithm
Arithmetic DDA algorithm uses floating points i.e. Real Bresenhams algorithm uses fixed points
Arithmetic. i.e. Integer Arithmetic.
Operations DDA algorithm Bresenhams algorithm uses
uses multiplication and division in its only subtraction and addition in its
operations. operations.
Speed DDA algorithm is rather slowly than Bresenhams algorithm is faster than DDA
Bresenhams algorithm in line drawing because in line drawing because it performs only
it uses real arithmetic (floating-point addition and subtraction in its calculation
operations). and uses only integer arithmetic so it
runs
Accuracy & DDA algorithm is not as accurate and Bresenhams algorithm is more efficient
Efficiency efficient as Bresenham algorithm. and much accurate than DDA algorithm.
Drawing DDA algorithm can draw circles and curves Bresenhams algorithm can draw circles
but that are not as accurate as Bresenhams and curves with much more accuracy
algorithm. than DDA algorithm.
Round Off DDA algorithm round off the coordinates to Bresenhams algorithm does not round
integer that is nearest to the line. off but takes the incremental value in its
operation.
Expensive DDA algorithm uses an enormous number of Bresenhams algorithm is less expensive
floating-point multiplications so it is than DDA algorithm as it uses only
expensive. addition and subtraction.

You might also like