Digital differential analyzer (graphics algorithm): Difference between revisions

Content deleted Content added
No edit summary
Tags: Reverted Mobile edit Mobile web edit
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)
 
(3 intermediate revisions by 3 users not shown)
Line 1:
khayam{{short description|Hardware or software used for interpolation of variables over an interval}}
 
I’mswgar khayami
khayam{{short description|Hardware or software used for interpolation of variables over an interval}}
{{About|a graphics algorithm|the digital implementation of a differential analyzer|Digital differential analyzer}}
 
Line 36 ⟶ 34:
 
== Program ==
DDA algorithm Programprogram in Turbo [[C++]]:
 
<syntaxhighlight lang="c++cpp" line="1">
#include <graphics.h>
#include <iostream.h>
Line 45 ⟶ 43:
#include <conio.h>
 
void main( )
{
float x,
Line 61 ⟶ 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 = 10;
 
while (i <= step) {
putpixel(round(x), round(y), 5);
x = x + dx;
y = y + dy;
Line 77 ⟶ 78:
delay(100);
}
 
getch();
closegraph();
Line 98 ⟶ 100:
[[Category:Computer graphics algorithms]]
[[Category:Digital geometry]]
[[Category:Articles with example C++ code]]