Einzelnen Beitrag anzeigen

Popov
(Gast)

n/a Beiträge
 
#5

AW: Linie mit bestimmter Länge und Winkel zeichnen

  Alt 26. Apr 2014, 23:52
Ich hab eine neue Funktion erstellt, dieses Mal mit sechs Richtungen. Die Bezeichnungen sind auch anders:
Delphi-Quellcode:
type
  TIsoOrientation2 = (ioL, ioR, ioV, ioH, ioO, ioU);

procedure DrawIsoLinie2(Canvas: TCanvas; Orientation: TIsoOrientation2; x1, y1, cLength: Integer; var x2, y2: Integer);
var
  a, b: Double;
begin
  a := cLength * Sin(DegToRad(30));
  b := Sqrt(Sqr(cLength) - Sqr(a));

  case Orientation of
    ioH : begin
            x2 := x1 - Round(b);
            y2 := y1 - Round(a);
          end;
    ioV : begin
            x2 := x1 + Round(b);
            y2 := y1 + Round(a);
          end;
    ioR : begin
            x2 := x1 + Round(b);
            y2 := y1 - Round(a);
          end;
    ioL : begin
            x2 := x1 - Round(b);
            y2 := y1 + Round(a);
          end;
    ioO : begin
            x2 := x1;
            y2 := y1 - cLength;
          end;
    ioU : begin
            x2 := x1;
            y2 := y1 + cLength;
          end;
  end;

  Canvas.MoveTo(x1, y1);
  Canvas.LineTo(x2, y2);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  x, y, x1, y1, x2, y2, x3, y3, Laenge: Integer;
begin
  x := 300;
  y := 300;
  Laenge := 100;

  //Ein Karton
  DrawIsoLinie2(Canvas, ioR, x, y, Laenge, x, y);
  DrawIsoLinie2(Canvas, ioO, x, y, Laenge, x, y);
  DrawIsoLinie2(Canvas, ioL, x, y, Laenge, x, y);
  DrawIsoLinie2(Canvas, ioU, x, y, Laenge, x, y);
  DrawIsoLinie2(Canvas, ioH, x, y, Laenge + 20, x, y);
  DrawIsoLinie2(Canvas, ioR, x, y, Laenge, x, y);
  x1 := x;
  y1 := y;
  DrawIsoLinie2(Canvas, ioO, x, y, Laenge, x, y);
  x2 := x;
  y2 := y;
  DrawIsoLinie2(Canvas, ioL, x, y, Laenge, x, y);
  x3 := x;
  y3 := y;
  DrawIsoLinie2(Canvas, ioU, x, y, Laenge, x, y);
  DrawIsoLinie2(Canvas, ioV, x1, y1, Laenge + 20, x, y);
  DrawIsoLinie2(Canvas, ioV, x2, y2, Laenge + 20, x, y);
  DrawIsoLinie2(Canvas, ioV, x3, y3, Laenge + 20, x, y);
end;
  Mit Zitat antworten Zitat