Skip to main content

DDA Line Drawing Algorithm

DDA Line Drawing Algorithm
Hey friends, this post is all about drawing a line using DDA Line Drawing Algorithm.


Digital Differential Analyzer (DDA) algorithm is the simple line generation algorithm.
DDA is hardware or software used for interpolation of variables over an interval between start and end point. DDAs are used for rasterization of lines, triangles and polygons.


Below is a program written in C to draw a simple line using DDA Line Drawing Algorithm.

Code:

/*
Title: DDA Line Drawing Algorithm
Description: C Program to draw a line by using DDA Algorithm
Author: Saideep Dicholkar
*/
#include<stdio.h>
#include<graphics.h>
#include<math.h>
void main()
{
int gd=DETECT,gm,x,y,x1,y1,x2,y2,dx,dy,i;
float length,xinc,yinc;
initgraph(&gd,&gm,"C:\\tc\\bgi");
cleardevice();
printf("Enter x1,y1,x2,y2:");
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
dx=x2-x1;
dy=y2-y1;
if(abs(dx)>=abs(dy))
length=abs(dx);
else
length=abs(dy);
xinc=dx/length;
yinc=dy/length;
x=x1;
y=y1;
putpixel((int)x,(int)y,WHITE);
i=0;
while(i<=length)
{
x=x+xinc;
y=y+yinc;
putpixel((int)x,(int)y,WHITE);
delay(100);
i=i+1;
}
getch();
closegraph();
restorecrtmode();
}
view raw dda.c hosted with ❤ by GitHub
If you can't see the code, then Enable JavaScript in you browser

Output:


Output of DDA Line Drawing Algorithm
Line using DDA Line Drawing Algorithm


Comments

Popular posts from this blog

Bresenham's Line Algorithm (THICK LINE)

Bresenham's Line Algorithm (THICK LINE) Bresenham's Line Algorithm (THICK LINE) The Bresenham algorithm is an incremental scan conversion algorithm.

Bresenham's Line Algorithm (DASHED LINE)

Bresenham's Line Algorithm (DASHED LINE) The Bresenham algorithm is an incremental scan conversion algorithm.

Bresenham's Line Algorithm (DOTTED LINE)

Bresenham's Line Algorithm (DOTTED LINE) Bresenham's Line Algorithm (DOTTED LINE) Bresenham's Line Algorithm (DOTTED LINE) The Bresenham algorithm is an incremental scan conversion algorithm.



Bestseller's in Electronics only at Amazon Best Selling Products on Amazon