![]() |
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:
[edit=Panthrax]Zum besseren Verständnis ein Bild angehangen.[/edit]
Schritte(4,4, 1,2) = 4; // Distanz ist nicht korrekt
Distanz(Punkt(4,4),Punkt(1,2)) = 3; // korrekte Distanz |
Re: Algorithmus gesucht: Abstand von zwei Hexagons
Zitat:
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 00:19 Uhr. |
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