// Ellipse um ein Rechteck
procedure Ellipse_aussen(cnv: TCanvas; x1, y1, x2, y2: integer; Farbe: TColor);
var
dy, dx, xx1, yy1, yy2, xx2: integer;
dff, wrzl2: double;
begin
cnv.pen.color := Farbe;
dx := (x2 - x1);
dy := (y2 - y1);
wrzl2 := sqrt(2);
dff := (dy * wrzl2 - dy) / 2;
yy1 := round(y1 - dff);
yy2 := round(y2 + dff);
dff := (dx * wrzl2 - dx) / 2;
xx1 := round(x1 - dff);
xx2 := round(x2 + dff);
cnv.ellipse(xx1, yy1, xx2, yy2);
end;
// Rechteck innerhalb einer Ellipse
procedure Rechteck_innen(cnv: TCanvas; x1, y1, x2, y2: integer; Farbe: TColor);
var
dy, dx, xx1, yy1, yy2, xx2: integer;
dff, wrzl2: double;
begin
cnv.pen.color := Farbe;
dx := (x2 - x1);
dy := (y2 - y1);
wrzl2 := sqrt(2);
dff := (dy / wrzl2 - dy) / 2;
yy1 := round(y1 - dff);
yy2 := round(y2 + dff);
dff := (dx / wrzl2 - dx) / 2;
xx1 := round(x1 - dff);
xx2 := round(x2 + dff);
cnv.rectangle(xx1, yy1, xx2, yy2);
end;
// Kreis um ein Rechteck
procedure Kreis_aussen(cnv: TCanvas; x1, y1, x2, y2: integer; Farbe: TColor);
var
dx, dy, c: integer;
begin
cnv.pen.color := Farbe;
dx := x2 - x1;
dy := y2 - y1;
c := round(sqrt(sqr(dx) + sqr(dy)) / 2);
dx := round(dx / 2) + x1;
dy := round(dy / 2) + y1;
cnv.ellipse(dx - c, dy - c, dx + c, dy + c);
end;
//-------------------------------------------------------------
// Beispielaufruf Ellipse
procedure TForm1.Button1Click(Sender: TObject);
var x1, x2, y1, y2: integer;
begin
x1 := 100;
y1 := 100;
x2 := 200;
y2 := 150;
Canvas.brush.style := bsClear;
Canvas.pen.color := clBlack;
Canvas.rectangle(x1, y1, x2, y2);
Ellipse_aussen(Canvas, x1, y1, x2, y2, clBlue);
end;
// Beispielaufruf Rechteck
procedure TForm1.Button2Click(Sender: TObject);
var x1, x2, y1, y2: integer;
begin
x1 := 279;
y1 := 90;
x2 := 421;
y2 := 160;
Canvas.brush.style := bsClear;
Canvas.pen.color := clBlue;
Canvas.ellipse(x1, y1, x2, y2);
Rechteck_innen(Canvas, x1, y1, x2, y2, clBlack);
end;
// Beispielaufruf Kreis
procedure TForm1.BitBtn2Click(Sender: TObject);
var x1, x2, y1, y2: integer;
begin
x1 := 100;
y1 := 100;
x2 := 200;
y2 := 150;
Canvas.brush.style := bsClear;
Canvas.pen.color := clBlack;
Canvas.rectangle(x1, y1, x2, y2);
Kreis_aussen(Canvas, x1, y1, x2, y2, clRed);
end;