Aneeket.15114802719@cse - Mait.ac: Experiment 2
Aneeket.15114802719@cse - Mait.ac: Experiment 2
Aneeket.15114802719@cse - Mait.ac: Experiment 2
ac
Experiment 2
AIM :- Implementation of DDA line Algorithm
THEORY :- DDA Algorithm is the simplest line drawing algorithm. Given the
starting and ending coordinates of a line, DDA Algorithm attempts to generate the
points between the starting and ending coordinates. In any 2-Dimensional plane if
we connect two points (x0, y0) and (x1, y1), we get a line segment. But in the case of
computer graphics we can not directly join any two coordinate points, for that we
should calculate intermediate point’s coordinate and put a pixel for each intermediate
point, of the desired colour with help of functions like putpixel(x, y, K) in C, where (x,
y) is our co-ordinate and K denotes some colour.
A DDA (Digital Differential Analyzer) algorithms is a scan-conversion method
for drawing a line which follows an incremental approach. In this algorithm to draw a
line the difference in the pixel points is analysed then according to that the line is
drawn. The method is said to be incremental because it performs computations at
each step and uses the outcome of the previous step.
SOURCE CODE:-
HUT :
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
int I;
float x,y,dx,dy,steps;
dx = (float)(x1 - x0);
dy = (float)(y1 - y0);
steps = dx;
else{
steps = dy;
dx = dx/steps;
dy = dy/steps;
x = x0;
y = y0;
i = 1;
while(i<=steps){
putpixel(x, y, BLUE);
x += dx;
y += dy;
i = i+1;
main() {
initwindow(800,800);
dda(100,100,200,200);
dda(100,100,325,100);
dda(200,200,400,200);
dda(325,100,400,200);
dda(200,200,20,200);
dda(20,200,100,100);
dda(400,200,400,400);
dda(20,400,400,400);
dda(20,200,20,400);
dda(200,200,200,400);
dda(65,290,65,400);
dda(150,290,150,400);
dda(65,290,150,290);
getch();
closegraph();
Output :-