Einzelnen Beitrag anzeigen

Blup

Registriert seit: 7. Aug 2008
Ort: Brandenburg
1.429 Beiträge
 
Delphi 10.4 Sydney
 
#2

AW: Hilfe bei Schleifenerstellung für HexfeldGitter

  Alt 8. Feb 2011, 08:20
Code:
  x0 x1        x2  x3

y0    __________
     /          \
    /            \
y1 /              \
   \              /
    \            /
y2   \__________/

Anzahl Spalten
dx1 = x1 - x0 = x3 - x2
dx2 = x2 - x1

nx = (Breite - dx1) div (dx1 + dx2)

Anzahl Zeilen
dy = y1 - y0 = y2 - y1

ny = (Höhe - dy) div dy

Als Bezugspunkt würde ich nicht die Mitte, sondern die linke obere Ecke des Rechtecks wählen, in dem das Hexagon gezeichnet wird (x0, y0).

Edit:
Die Zeilen sind eigentlich Halbzeilen.
Delphi-Quellcode:
  for y := 0 to ny - 1 do
  begin
    y0 := y * dy;
    if Odd(y) then
    begin
      x0 := dx1 + dx2;
      n := nx div 2;
    end
    else
    begin
      x0 := 0;
      n := (nx + 1) div 2;
    end;

    for x := 0 to n - 1 do
    begin
      HexFeldDraw(x0, y0, dx1, dx2, dy);
      x0 := x0 + dx1 + dx2 + dx1 + dx2;
    end;
  end;

Geändert von Blup ( 8. Feb 2011 um 08:57 Uhr)
  Mit Zitat antworten Zitat