unit MBaum01;
interface
uses
UConfig,
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, Math;
type
TForm1 = class(TForm)
Image1: TImage;
Paint: TButton;
procedure FormCreate(Sender: TObject);
private
Auswahl: Integer;
zaehler: Integer;
OldAlpha: Double;
Ast,i,j,row: Integer;
a,b,c,c1, alpha, beta, gamma: Double;
procedure PaintTree_Dreieck(XPoint1,YPoint1,XPoint2,YPoint2: Integer);
procedure PaintTree_Viereck(XPoint1,YPoint1,XPoint2,YPoint2: Integer);
procedure PaintTree_NewViereck(XPoint1,YPoint1,XPoint2,YPoint2: Integer);
public
SeitenLaenge: array [1..QUADRATE] of array [0..5] of Double;
Old_alpha : array [1..QUADRATE] of array [0..5] of Double;
X_Point1 : array [1..QUADRATE] of array [0..5] of Integer;
Y_Point1 : array [1..QUADRATE] of array [0..5] of Integer;
X_Point2 : array [1..QUADRATE] of array [0..5] of Integer;
Y_Point2 : array [1..QUADRATE] of array [0..5] of Integer;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
// ShowMessage(FloatToStr(power(2,12)));
Image1.Width := IMGWIDTH;
Image1.Height := IMGHEIGHT;
Form1.Width := IMGWIDTH + 10;
Form1.Height := IMGHEIGHT + 60;
Paint.Top := IMGHEIGHT + 4;
Paint.Left := 0;
Image1.Canvas.Rectangle(IMGWIDTH div 2 - VIERECK div 2, IMGHEIGHT - VIERECK,
IMGWIDTH div 2 + VIERECK div 2, IMGHEIGHT);
c := VIERECK;
i := 0;
j := 1;
row := 0;
Auswahl := 1;
zaehler := 0;
Ast := Tiefe;
PaintTree_Dreieck(IMGWIDTH div 2 - VIERECK div 2,IMGHEIGHT - VIERECK,
IMGWIDTH div 2 + VIERECK div 2,IMGHEIGHT - VIERECK);
end;
procedure TForm1.PaintTree_Dreieck(XPoint1,YPoint1,XPoint2,YPoint2: Integer);
var
YHilfsPoint, XHilfsPoint: Integer;
begin
gamma := 90;
a := c/1.41;
b := sqrt((c*c) - (a*a));
c1 := b;
alpha := arcsin(a * sin(gamma/180*PI) / c) * (180/PI);
OldAlpha := OldAlpha + alpha;
c := b;
// Dreieckberechnung
gamma := 90;
alpha := 90 - OldAlpha;
beta := 180 - gamma - alpha;
XHilfsPoint := Round(XPoint1+(c * sin(alpha/180*PI) / sin(gamma/180*PI)));
YHilfsPoint := Round(YPoint1-(c * sin(beta/180*PI) / sin(gamma/180*PI)));
zaehler := zaehler + 1;
// Berechnung für den OberenPunkt (Punkt C)
if zaehler <= Ast then begin // ersterdruchschlauf
Image1.Canvas.Polygon([Point(XPoint1,YPoint1),Point(XPoint2,YPoint2),
Point(XHilfsPoint,YHilfsPoint)]);
PaintTree_NewViereck(XHilfsPoint,YHilfsPoint,XPoint2,YPoint2); // Viereck Rechteseite Dreieck
PaintTree_Viereck(XPoint1,YPoint1,XHilfsPoint,YHilfsPoint); // Viereck Linkeseite Dreieck
end else if ast <> 1 then begin // aufbau das Bames Linkes Viereck
i := i + 1;
Ast := Ast - 1;
zaehler := ast-i;
Oldalpha := Old_alpha[Tiefe-i,0] - 90;
c := SeitenLaenge[Tiefe-i,0];
// neue Werte fürs Dreieck zugewiesen
PaintTree_Dreieck(X_Point1[Tiefe-i,0],Y_Point1[Tiefe-i,0],X_Point2[Tiefe-i,0],Y_Point2[Tiefe-i,0]); // Dreieck zeichnen
end
else begin
//---->anfang-test<---
// ast := Tiefe;
// PaintTree_Dreieck(X_Point1[row,0],Y_Point1[row,0],X_Point2[row,0],Y_Point2[row,0]);
Image1.Canvas.Pen.Color := clRed;
Image1.Canvas.MoveTo(X_Point1[row-4,0],Y_Point1[row-4,0]);
Image1.Canvas.LineTo(X_Point2[row-4,0],Y_Point2[row-4,0]);
Image1.Canvas.Pen.Color := clBlack;
//----->Yende-test<----
end;
end;
procedure TForm1.PaintTree_Viereck(XPoint1,YPoint1,XPoint2,YPoint2: Integer);
var
XHPoint1, YHPoint1: Integer;
YHilfsPoint, XHilfsPoint: Integer;
begin
XHPoint1 := XPoint1;
YHPoint1 := YPoint1;
alpha := 90;
beta := 180 - 90 - oldalpha;
gamma := 180 - alpha - beta;
XPoint1 := Round(XPoint1-(c * sin(gamma/180*PI) / sin(alpha/180*PI)));
YPoint1 := Round(YPoint1-(c * sin(beta/180*PI) / sin(alpha/180*PI)));
XHilfsPoint := Round(XPoint1+(c * sin(beta/180*PI) / sin(alpha/180*PI)));
YHilfsPoint := Round(YPoint1-(c * sin(gamma/180*PI) / sin(alpha/180*PI)));
Image1.Canvas.Polygon([Point(XHPoint1,YHPoint1),Point(XPoint1,YPoint1),
Point(XHilfsPoint,YHilfsPoint),Point(XPoint2,YPoint2)]); // Viereckzeichnen
PaintTree_Dreieck(XPoint1,YPoint1,XHilfsPoint,YHilfsPoint); //Dreieck aufrufen
end;
procedure TForm1.PaintTree_NewViereck(XPoint1,YPoint1,XPoint2,YPoint2: Integer);
var
XHPoint2, YHPoint2: Integer;
XHPoint1, YHPoint1: Integer;
begin
alpha := 90;
beta := 180 - 90 - oldalpha;
gamma := 180 - alpha - beta;
XHPoint2 := XPoint2;
YHPoint2 := YPoint2;
XHPoint1 := XPoint1;
YHPoint1 := YPoint1;
XPoint2 := Round(XHPoint2+(a * sin(beta/180*PI) / sin(alpha/180*PI)));
YPoint2 := Round(YHPoint2-(a * sin(gamma/180*PI) / sin(alpha/180*PI)));
XPoint1 := Round(XPoint2-(a * sin(gamma/180*PI) / sin(alpha/180*PI)));
YPoint1 := Round(YPoint2-(a * sin(beta/180*PI) / sin(alpha/180*PI)));
Image1.Canvas.Polygon([Point(XHPoint1,YHPoint1),Point(XPoint1,YPoint1),
Point(XPoint2,YPoint2),Point(XHPoint2,YHPoint2)]); //Viereckzeichnen
row := row +1;
SeitenLaenge[row,0]:= a;
Old_alpha[row,0] := Oldalpha;
X_Point1[row,0] := XPoint1;
Y_Point1[row,0] := YPoint1;
X_Point2[row,0] := XPoint2;
Y_Point2[row,0] := YPoint2;
//Werte speichern
end;
end.