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: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206:
| unit Kreis;
interface
uses SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls, Math ;
type TFormImage = class(TForm) PaintBox1: TPaintBox; Button1: TButton;
procedure pbreset(Sender: TObject); procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
private FClick1: TPoint; FClick2: TPoint; FClick3: TPoint; public end;
var FormImage: TFormImage;
implementation
{$R *.DFM}
procedure TFormImage.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var n: string; m: string; mp: TPoint; pr1: TPoint; pr2: TPoint; r,p,h,u,i,xr1,xr2,yr1,yr2: Integer; b,ms,sp,z,alp,bet,gam,del: Extended; begin if (FClick1.X = 0) and (FClick1.Y = 0) then begin FClick1 := Point(X, Y); Paintbox1.Canvas.Rectangle(0,0,800,600); with PaintBox1.Canvas do begin moveto(FClick1.X-4,FClick1.Y); lineto(FClick1.X+5,FClick1.Y); moveto(FClick1.X,FClick1.Y-4); lineto(FClick1.X,FClick1.Y+5); end; end else if (FClick2.X = 0) and (FClick2.Y = 0) then begin FClick2 := Point(X, Y); r := round(sqrt(sqr(FClick1.X - FClick2.X) + sqr(FClick1.Y-FClick2.Y))); if (FClick1.X - r < 0) or (FClick1.Y - r < 0) or (FClick1.X + r > 787) or (FClick1.Y + r > 529) then begin FClick1 := Point(0, 0); FClick2 := Point(0, 0); FClick3 := Point(0, 0);
Paintbox1.Canvas.Rectangle(0,0,800,600); n:='Der Radius ist zu groß Gewäht, der Kreis kann nich vollständig dargestellt werden!'; Paintbox1.Canvas.TextOut(50,250, n);
end else
if (FClick1.X - r > 0) or (FClick1.Y - r > 0) and (FClick1.X + r < 787) or (FClick1.Y + r < 529) then begin Paintbox1.Canvas.Ellipse(FClick1.X - r, FClick1.Y - r, FClick1.X + r, FClick1.Y + r); with PaintBox1.Canvas do begin moveto(FClick1.X-4,FClick1.Y); lineto(FClick1.X+5,FClick1.Y); moveto(FClick1.X,FClick1.Y-4); lineto(FClick1.X,FClick1.Y+5); end; end end else if (FClick3.X = 0) and (FClick3.Y = 0) then begin FClick3 := Point(X, Y); p:= round(sqrt(sqr(FClick1.X - FClick3.X) + sqr(FClick1.Y-FClick3.Y))); r := round(sqrt(sqr(FClick1.X - FClick2.X) + sqr(FClick1.Y-FClick2.Y))); if (p < r) then begin FClick1 := Point(0, 0); FClick2 := Point(0, 0); FClick3 := Point(0, 0);
Paintbox1.Canvas.Rectangle(0,0,800,600); m:='Der Punkt P liegt innerhalb vom Kreis'; Paintbox1.Canvas.TextOut(50,250, m);
end else if (p > r) then begin b:= (sqrt(sqr(p) - sqr(r))); h:=round((r*b)/p); ms:= (sqrt(sqr(r) - sqr(h))); sp:= p-ms; z:= sp/p; u:= round((-z+1)*(FClick3.x-FClick1.X)+FClick1.X); i:= round((-z+1)*(FClick3.y-FClick1.Y)+FClick1.Y); mp:= Point(u,i); if (FClick1.X = FClick3.X) then Begin pr1:= Point(mp.X+h,mp.Y); pr2:= Point(mp.X-h,mp.Y); end else
if (FClick1.X < FClick3.X) then Begin alp:= ArcSin(((FClick3.Y - FClick1.Y))/p); bet:= ArcSin (r/p); gam:= alp + bet ; del:= alp - bet ; xr1:=round( (b * cos(gam))); yr1:=round( (b * sin(gam))); xr2:=round( (b * cos(del))); yr2:=round( (b * sin(del)));
pr1:= Point(FClick3.X-xr1,FClick3.Y-yr1); pr2:= Point(FClick3.X-xr2,FClick3.Y-yr2); end else if (FClick1.X > FClick3.X) then Begin alp:= ArcSin(((FClick3.Y - FClick1.Y))/p); bet:= ArcSin (r/p); gam:= alp + bet ; del:= alp - bet ; xr1:=round( (b * cos(-gam))); yr1:=round( (b * sin(-gam))); xr2:=round( (b * cos(-del))); yr2:=round( (b * sin(-del)));
pr1:= Point(FClick3.X+xr1,FClick3.Y+yr1); pr2:= Point(FClick3.X+xr2,FClick3.Y+yr2); end;
with paintbox1.Canvas do begin moveto(FClick1.X-4,FClick1.Y); lineto(FClick1.X+5,FClick1.Y); moveto(FClick1.X,FClick1.Y-4); lineto(FClick1.X,FClick1.Y+5); moveto(FClick3.X-4,FClick3.Y); lineto(FClick3.X+5,FClick3.Y); moveto(FClick3.X,FClick3.Y-4); lineto(FClick3.X,FClick3.Y+5); moveto(FClick1.X,FClick1.Y); lineto(FClick3.X,FClick3.Y); moveto(mp.x-4,mp.y); lineto(mp.x+5,mp.y); moveto(mp.x,mp.y-4); lineto(mp.x,mp.y+5); moveto(pr1.x-4,pr1.y); lineto(pr1.x+5,pr1.y); moveto(pr1.x,pr1.y-4); lineto(pr1.x,pr1.y+5); moveto(pr2.x-4,pr2.y); lineto(pr2.x+5,pr2.y); moveto(pr2.x,pr2.y-4); lineto(pr2.x,pr2.y+5); moveto(pr2.x,pr2.y); lineto(pr1.x,pr1.y); moveto(pr2.x,pr2.y); lineto(FClick3.X,FClick3.Y); lineto(pr1.x,pr1.y);
end; end; end; end;
procedure TFormImage.pbreset(Sender: TObject); begin
FClick1 := Point(0, 0); FClick2 := Point(0, 0); FClick3 := Point(0, 0);
Paintbox1.Canvas.Rectangle(0,0,800,600); end;
end. |