jk@utastro.UUCP (John Krist) (02/11/86)
Well, just after I finished with the update article, I began modifying the graphics routines for the DSI-32 virtual graphics library. I decided to substitute the included line drawing routine with the DDA routine show here. After I coded it, I tested it for speed and such just by timing (no pixel mapping routines included, just the calculations). To my suprise, I got the wrong answer. I converted it to fortran and got the right answer, so I tested it on the VAX here, and also got the right answer with the same identical C code - 20001.5. My C gives me 19893.5 ! If anyone out there can run this on there DSI and get the right results, please tell me (I've got the December 1985 dated compilers). Thanks, John Krist {allegra,ihnp4}!{noao,ut-sally}!utastro!jk DDA line drawing code: #include <math.h> #include <stdio.h> main() { float x1,x2,y1,y2,rlength,xinc,yinc,x,y; int i; x1=0.; x2=20000.; y1=0.; y2=20000.; rlength = fabs ( x2-x1 ); if (fabs( y2-y1 ) > rlength ) rlength = fabs ( y2-y1 ); xinc = ( x2-x1 ) / rlength; yinc = ( y2-y1 ) / rlength; x = x1 + .5; y = y1 + .5; while ( i <= rlength ) { x = x + xinc; y = y + yinc; i++; } printf ("%.6f\n",x); }
devoz@encore.UUCP (Joe Devincentis) (02/18/86)
[eat at joes]
As my modem is also eating things, I will be brief.
The i variable is never initialized, making this loop dependent on Zuut for
luck.
while ( i <= rlength )
{
x = x + xinc;
y = y + yinc;
i++;
}
printf ("%.6f\n",x);
Lint caught this for me right away.
devoz@encore
Joe DeVincentis