Einzelnen Beitrag anzeigen

Bjoerk

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

AW: aus einer Liste Einträge in eine andere Liste verschieben

  Alt 11. Sep 2014, 18:14
Weiß nicht mehr, würde sagen ja. Habs jetzt auch "anständig" gemacht, da sieht die Flip auch schon wesentlich gemütlicher aus. Flip bedeutet Kantenflip bei benachbarten Dreiecken, die zusammen eine Raute bilden. Da werden die beiden Dreiecke in der anderen Möglichkeit diese Raute zu bilden angeordnet, falls ein gewisses Seitenverhältnis überschritten ist.

Delphi-Quellcode:
function TPolygonTriangle.IndexOf(const Value: TFLoatPoint): integer;
begin
  Result := -1;
  if Util_SameFloatPoint(Value, A) then
    Result := 0
  else
    if Util_SameFloatPoint(Value, B) then
      Result := 1
    else
      if Util_SameFloatPoint(Value, C) then
        Result := 2;
end;

function TPolygonTriangle.Compare(const Value: TPolygonTriangle): boolean;
begin
  Result := (IndexOf(Value.A) > 0) and (IndexOf(Value.B) > 0)
    and (IndexOf(Value.C) > 0)
end;

function TPolygonTriangle.Adjacent(const Value: TPolygonTriangle): boolean;
begin
  Result := (IndexOf(Value.A) > 0) and (IndexOf(Value.B) > 0)
    or (IndexOf(Value.A) > 0) and (IndexOf(Value.C) > 0)
    or (IndexOf(Value.B) > 0) and (IndexOf(Value.C) > 0);
end;

function TPolygonTriangle.FirstAdjacent(const Value: TPolygonTriangle): TFloatPoint;
var
  I, J: integer;
  P1, P2: array[0..2] of TFloatPoint;
begin
  // Self and Value müssen Adjacent Items sein;
  Result.Clear;
  P1[0] := A;
  P1[1] := B;
  P1[2] := C;
  P2[0] := Value.A;
  P2[1] := Value.B;
  P2[2] := Value.C;
  for I := 0 to 2 do
    for J := 0 to 2 do
      if Util_SameFloatPoint(P1[I], P2[J]) then
      begin
        Result := P1[I];
        Exit;
      end;
end;

function TPolygonTriangle.SecondAdjacent(const Value: TPolygonTriangle): TFLoatPoint;
var
  I, J: integer;
  P1, P2: array[0..2] of TFloatPoint;
begin
  // Self and Value müssen Adjacent Items sein;
  Result.Clear;
  P1[0] := A;
  P1[1] := B;
  P1[2] := C;
  P2[0] := Value.A;
  P2[1] := Value.B;
  P2[2] := Value.C;
  for I := 0 to 2 do
    for J := 0 to 2 do
      if Util_SameFloatPoint(P1[I], P2[J]) then
        Result := P1[I];
end;

function TPolygonTriangle.NotAdjacent(const Value: TPolygonTriangle): TFLoatPoint;
var
  P1, P2: TFloatPoint;
begin
  // Self and Value müssen Adjacent Items sein;
  P1 := FirstAdjacent(Value);
  P2 := SecondAdjacent(Value);
  if (not Util_SameFloatPoint(P1, A)) and (not Util_SameFloatPoint(P2, A)) then
    Result := A
  else
    if (not Util_SameFloatPoint(P1, B)) and (not Util_SameFloatPoint(P2, B)) then
      Result := B
    else
      Result := C;
end;


// ..

procedure TPolygonTriangles.Flip;
var
  I, J: integer;
  SCur, SNew: double;
  A1, A2, A3, B3: TFLoatPoint;
begin
  for I := 0 to Count - 2 do
    for J := I + 1 to Count - 1 do
      if Item[I].Adjacent(Item[J]) then
      begin
        A1 := Item[I].FirstAdjacent(Item[J]);
        A2 := Item[I].SecondAdjacent(Item[J]);
        A3 := Item[I].NotAdjacent(Item[J]);
        B3 := Item[J].NotAdjacent(Item[I]);
        SCur := Util_FloatPointDistance(A1, A2);
        SNew := Util_FloatPointDistance(A3, B3);
        if SCur / SNew > 1.5 then
        begin
          Item[I].A := A1;
          Item[I].B := A3;
          Item[I].C := B3;
          Item[J].A := A3;
          Item[J].B := A2;
          Item[J].C := B3;
        end;
      end;
end;
  Mit Zitat antworten Zitat