Autor Beitrag
Flamefire
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Fr 18.05.07 21:36 
Ich habe mal den Bresenham-Algorithmus implementiert (wikipedia: de.wikipedia.org/wik...resenham-Algorithmus )

aber da scheint ein fehler zu sein...
meine linie deckt sich nicht mit einer, die von ner andren implementirung genau des gleichen algos gemacht wurde.
kann jmd mal drüberschaun?

(Tposarray: Array of Array[0..1] of Integer)
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
procedure gbham(xstart,ystart,xend,yend:Integer;var npix:Integer;var koords:Tposarray);
var x, y, t, dist, xerr, yerr, dx, dy, incx, incy:Integer;
begin
// Entfernung in beiden Dimensionen berechnen
     dx:=xend - xstart;
     dy:=yend - ystart;
// Vorzeichen des Inkrements bestimmen
     if(dx<0)then begin
       incx:=-1;
       dx:=-dx;
     end else if (dx > 0) then incx:=1
     else incx:=0;
     if(dy<0) then begin
       incy:=-1;
       dy:=-dy;
     end else if (dy > 0) then incy:=1
     else incy:=0;
// feststellen, welche Entfernung größer ist
     dist:=dy;
     if(dx>=dy) then dist:=dx;
// Initialisierungen vor Schleifenbeginn
     x:=xstart;
     y:=ystart;
     xerr:=dx;
     yerr:=dy;
     npix:=dist+1;
     Setlength(koords,npix);
// Pixel berechnen
     for t:=0 to dist-1 do begin
       koords[t][0]:=x;
       koords[t][1]:=y;
       xerr:=xerr+dx;
       yerr:=yerr+dy;
       if(xerr>dist) then begin
         xerr:=xerr-dist;
         x:=x+incx;
       end;
       if(yerr>dist) then begin
         yerr:=yerr-dist;
         y:=y+incy;
       end;
     end;
     koords[dist][0]:=xend;
     koords[dist][1]:=yend;
end;


der ist nur aus der C-Version von Wikipedia übersetzt...aber anscheinend mit nem Fehler =(
arj
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 378

Win XP/Vista, Debian, (K)Ubuntu
Delphi 5 Prof, Delphi 7 Prof, C# (#Develop, VS 2005), Java (Eclipse), C++, QT, PHP, Python
BeitragVerfasst: Sa 19.05.07 16:51 
In Zeile 20 hast du ein >= im C Code ist ein >.
ausblenden Delphi-Quelltext
1:
if(dx>=dy) then dist:=dx;					

ausblenden C#-Quelltext
1:
dist = (dx > dy)?dx:dy;					


Mehr Fehler hab ich nicht entdeckt, aber vielleicht war das ja auch er springende Punkt :)
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 28

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Sa 19.05.07 17:00 
es muss aber:
ausblenden Delphi-Quelltext
1:
  dist := max(dx, dy);					

lauten.

mfg
Flamefire Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Sa 19.05.07 18:47 
dürfte ja ca. das gleiche sein...
seltsam...nja was solls