Content deleted Content added
m Reverted edits by 122.162.99.90 (talk) (HG) (3.4.10) |
→Program: The DDA algorithm requires rounding the floating point x,y to the nearest integer. The sample code should not depend on the behavior of some specific graphics library's putpixel() (for example if it takes int parameters, float->int uses truncation and will produce the wrong answer) |
||
(2 intermediate revisions by 2 users not shown) | |||
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;
x = x1;
y = y1;
i =
while (i <= step) {
putpixel(round(x), round(y), 5);
x = x + dx;
y = y + dy;
Line 75 ⟶ 78:
delay(100);
}
getch();
closegraph();
Line 96 ⟶ 100:
[[Category:Computer graphics algorithms]]
[[Category:Digital geometry]]
[[Category:Articles with example C++ code]]
|