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: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122:
| program konvexeHuelle; uses crt; const bell=7; breite=48; hoehe =24; var baumx,baumy:array[0..100] of integer; a,b:array[1..2] of integer; LMAX,la,lb,winkel,max:real; zeichen,taste:char; ymax,i,anzahl,anfang,neu,min,zaun,p1,p2,p3:integer; procedure plot(k:integer); begin gotoxy(baumx[k],hoehe-baumy[k]+1); write(zeichen);write(chr(bell)) end; function frei(k:integer):boolean; var i:integer; besetzt:boolean; begin besetzt:=false;i:=1; while (i<>k) and (not besetzt) do begin if (baumx[i]=baumx[k]) and (baumy[i]=baumy[k]) then besetzt:=true; i:=i+1 end; frei:=not besetzt; end;
procedure bestimme; begin randomize; for i:=1 to anzahl do begin repeat baumx[i]:=random(breite)+1; baumy[i]:=random(hoehe)+1 until frei(i) end end; procedure eingabe; var x,y:integer; begin for i:=1 to anzahl do begin repeat write('baumnr.',i:4,' (x y): '); readln(x,y); x:=abs(x);x:=x mod (breite)+1; y:=abs(y);y:=y mod (hoehe)+1; baumx[i]:=x;baumy[i]:=y until frei(i) end end; begin clrscr; repeat write('positionen (b)estimmen lassen'); write('oder (e)ingeben?'); taste:=readkey until taste in ['b','B','e','E']; writeln(taste); repeat write('wieviele baeume?'); readln(anzahl) until anzahl in [1..100]; if upcase(taste)='B' then bestimme else eingabe; zeichen:='*';clrscr; for i:=1 to anzahl do plot(i); min:=2*breite;ymax:=0; for i:=1 to anzahl do begin if baumx[i]<min then begin min:=baumx[i]; anfang:=i;ymax:=baumy[i] end; if (baumx[i]=min) and (baumy[i]>ymax) then begin min:=baumx[i];anfang:=i; ymax:=baumy[i] end; end; ZEICHEN:='#';plot(anfang); baumx[0]:=baumx[anfang];baumy[0]:=2*hoehe; p1:=0;p2:=anfang;zaun:=0; repeat zaun:=zaun+1;neu:=anfang;gotoxy(50,zaun+4); writeln('pfahl',zaun:4,' bei x:',baumx[p2]:4,' y:',baumy[p2]:4); a[1]:=baumx[p1]-baumx[p2];a[2]:=baumy[p1]-baumy[p2]; lmax:=0;la:=sqrt(sqr(a[1])+sqr(a[2]));max:=breite; for p3:=1 to anzahl do begin if p3<>p2 then begin b[1]:=baumx[p3]-baumX[p2];b[2]:=baumy[p3]-baumy[p2]; lb:=sqrt(sqr(b[1])+sqr(b[2])); winkel:=(a[1]*b[1]+a[2]*b[2])/la/lb; if winkel<max then begin max:=winkel; neu:=p3;lmax:=lb end; if (winkel=max) and (lb>lmax) then begin max:=winkel; neu:=p3;lmax:=lb end; end end; plot(neu); p1:=p2;p2:=neu until neu=anfang; for i:=1 to 3 do write(chr(bell)); taste:=readkey end. |