0% found this document useful (1 vote)
498 views

DDA MAtLAB Programme

This function takes in x and y coordinates of two points and uses the Digital Differential Analyzer (DDA) algorithm to calculate the discrete points along the line between the two points. It outputs the actual points, rounded DDA points, and plots the two sets of points on a graph for comparison.

Uploaded by

Marsal CM
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
0% found this document useful (1 vote)
498 views

DDA MAtLAB Programme

This function takes in x and y coordinates of two points and uses the Digital Differential Analyzer (DDA) algorithm to calculate the discrete points along the line between the two points. It outputs the actual points, rounded DDA points, and plots the two sets of points on a graph for comparison.

Uploaded by

Marsal CM
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
You are on page 1/ 1

DDA Function:

function [ output_args ] = DDA( x1,y1,x2,y2 )


%DDA Summary of this function goes here
% Detailed explanation goes here
dx=abs(x2-x1)
dy=abs(y2-y1)
sx=sign(x2-x1)
sy=sign(y2-y1)
if dx>dy
step=dx;
else
step=dy;
end
j=1
point(j,1)=x1
point(j,2)=y1
ap(j,1)=x1
ap(j,2)=y1
for i=1:1:step
j=j+1
x=point(j-1,1)+sx*(dx/step);
y=point(j-1,2)+sy*(dy/step);
point(j,1)=x;
point(j,2)=y;
ap(j,1)=round(x);
ap(j,2)=round(y);
end

l=point(:,1)
m=point(:,2)
n=ap(:,1)
p=ap(:,2)
xlswrite('Actual points',point)
xlswrite('DDA points',ap)
plot(l,m,'g^',n,p,'b^')
legend('Actual Points','DDA Points')
title('Ex No 7 Reg No 1510057')
end
-----------------------------------------------------------------------------------
---------
Script:

point=input('Enter points : ')


x1=point(1)
y1=point(2)
x2=point(3)
y2=point(4)

DDA(x1,y1,x2,y2)

You might also like