Content deleted Content added
Fix bug in code -- i must start at 0 to include both endpoints of the line. Consider what happens when step is 0. See https://www.geeksforgeeks.org/dda-line-generation-algorithm-computer-graphics/ for the loop starting with 0 |
No edit summary |
||
Line 34:
== Program ==
DDA algorithm
<syntaxhighlight lang="
#include <graphics.h>
#include <iostream.h>
Line 43:
#include <conio.h>
void main(
{
float x,
Line 59:
dx = (x2 - x1);
dy = (y2 - y1);
if (abs(dx) >= abs(dy))
step = abs(dx);
else
step = abs(dy);
dx = dx / step;
dy = dy / step;
Line 68 ⟶ 70:
y = y1;
i = 0;
while (i <= step) {
putpixel(x, y, 5);
Line 75 ⟶ 78:
delay(100);
}
getch();
closegraph();
Line 96 ⟶ 100:
[[Category:Computer graphics algorithms]]
[[Category:Digital geometry]]
[[Category:Articles with example C++ code]]
|