menu
Ask
search
brightness_auto
more_vert
DDA Line drawing
thumb_up_off_alt 0 like thumb_down_off_alt 0 dislike

1 Answer

more_vert
 
verified
Best answer
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
#define ROUND(a) ((int)(a+0.5))
void lineDDA(int xa, int ya, int xb, int yb);
void main()
{
int xa, xb, ya, yb;
int gd=DETECT, gm, gerr;
clrscr();
printf("Enter the two end points [(xa, ya), (xb, yb)]:");
scanf("%d%d%d%d",&xa, &ya, &xb, &yb);
initgraph(&gd, &gm,"C:\\tc\\bgi);
gerr=graphresult();
if(gerr!=grOk)
{
printf("Error: %s",grapherrormsg(gerr));
getch();
return;
}
lineDDA(xa, ya, xb, yb);
getch();
closegraph();
}
void lineDDA(int xa, int ya, int xb, int yb);
{
int dx=xb-xa, dy=yb-ya, steps, k;
float xIncrement, yIncrement, x=xa, y=ya;
if(abs(dx)>abs(dy)
steps=abs(dx);
else
steps=abs(dy);
xIncrement=dx/(float)steps;
yIncrement=dy/(float)steps;
putpixel(ROUND(x), ROUND(y), RED);
for(k=0;k<steps;k++)
{
x+=xIncrement;
y+=yIncrement;
putpixel(ROUND(x), ROUND(y), RED);
}
}


https://elearning.raghunathpurcollege.ac.in/files/7084DE0116032653160.pdf
thumb_up_off_alt 0 like thumb_down_off_alt 0 dislike
This community is for Every Learner to help each other and ask doubts .

155 questions

134 answers

53 comments

148 users

...