Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   Delphi Algorithmus gesucht: Abstand von zwei Hexagons (https://www.delphipraxis.net/118873-algorithmus-gesucht-abstand-von-zwei-hexagons.html)

Panthrax 17. Aug 2008 17:14

Re: Algorithmus gesucht: Abstand von zwei Hexagons
 
Liste der Anhänge anzeigen (Anzahl: 1)
Delphi-Quellcode:
function Distanz(const P1, P2: TPoint): Integer;
var
  DeltaX, DeltaY: Integer;
begin
  DeltaX:=Abs(P1.X-P2.X);
  DeltaY:=Abs(P1.Y-P2.Y);
  if 2*DeltaY <= DeltaX then
    Result:=DeltaX
  else
    Result:=DeltaX+DeltaY
      { jeder 2. "X-Schritt" entspricht einem Y-Schritt }
      -((DeltaX+1) div 2)
      { X-Koordinate, X-Distanz und Y-Richtung sind bedeutsam }
      +Integer(Odd(DeltaX) and (
        (Odd(P1.X) and (P1.Y > P2.Y))
        or (not Odd(P1.X) and (P1.Y < P2.Y))
      ))
    ;
end;
Delphi-Quellcode:
Schritte(4,4, 1,2) = 4; // Distanz ist nicht korrekt
Distanz(Punkt(4,4),Punkt(1,2)) = 3; // korrekte Distanz
[edit=Panthrax]Zum besseren Verständnis ein Bild angehangen.[/edit]

Codewalker 17. Aug 2008 17:24

Re: Algorithmus gesucht: Abstand von zwei Hexagons
 
Zitat:

Zitat von Panthrax
Delphi-Quellcode:
Schritte(4,4, 1,2) = 4; // Distanz ist nicht korrekt
Distanz(Punkt(4,4),Punkt(1,2)) = 3; // korrekte Distanz

Stimmt, kann ich nachvollziehen. Distanz scheint nach ersten Versuchen korrekt zu sein


Alle Zeitangaben in WEZ +1. Es ist jetzt 00:19 Uhr.
Seite 2 von 2     12   

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz