Einzelnen Beitrag anzeigen

Bjoerk

Registriert seit: 28. Feb 2011
Ort: Mannheim
1.384 Beiträge
 
Delphi 10.4 Sydney
 
#1

Punkte in ein Polygon überführen

  Alt 10. Mai 2016, 21:21
Ich müßte für eine Triangulation Punkte in ein Polygon überführen. Der Algorithmus trianguliert jeweils die Punkte in einer Grid.Cell (Siehe Anlage). Der Algo benötigt die Punkte jeweils als rechtsdrehendes xor linksdrehendes Polygon. Konvex oder Konkav ist (hier) egal. Deshalb wollte ich Sortieren. Es sind in der Regel nur so 3 bis 6 Punkte je Cell. Das klappt aber nicht (immer). Überlegt hatte ich mir das. Klappt aber irgendwie nicht (immer). Jemand eine Idee? Wäre klasse.

Delphi-Quellcode:
function TFloatPoints.Counterclockwise(const Index: integer): boolean;
var
  A, B, C: TFloatPoint;
  x21, x31, y21, y31: double;
begin
  A := PrevItems[Index];
  B := Items[Index];
  C := NextItems[Index];
  x21 := B.X - A.X;
  x31 := C.X - A.X;
  y21 := B.Y - A.Y;
  y31 := C.Y - A.Y;
  Result := x21 * y31 - x31 * y21 > 0;
end;

procedure TFloatPoints.SortCounterclockwise;
var
  I, J: integer;
begin
  for I := 0 to Count - 2 do
    for J := I + 1 to Count - 1 do
      if not Counterclockwise(J) then
        Exchange(J, Next(J));
  for I := 0 to Count - 1 do
    if not Counterclockwise(I) then
      ShowMessage('not Counterclockwise');
end;
Miniaturansicht angehängter Grafiken
trianglemeshexample.jpg  
  Mit Zitat antworten Zitat