Einzelnen Beitrag anzeigen

Benutzerbild von Jonas Shinaniganz
Jonas Shinaniganz

Registriert seit: 30. Aug 2011
249 Beiträge
 
Delphi XE5 Ultimate
 
#19

AW: 2 Vektoren und 1 Punkt, wo näher drann?

  Alt 11. Apr 2012, 10:17
Okay Ich habe jetzt weitestgehend Antwort7 umgesetzt und auch einen Vektor2D eingeführt.

Delphi-Quellcode:
function TSetPoints.PrevLineCloser(Index : Integer; X, Y : Double): Boolean;
var
  NewPoint : TFloatPoint;

  A : TVector2d;
  B : TVector2d;
  B0 : TVector2d;
  H1, H2 : Double;

  PrevPoint, NextPoint, IndexPoint : TFloatPoint;

begin
  Result := True;

  NewPoint.X := X;
  NewPoint.Y := Y;

  PrevPoint.X := FPoints[Index - 1].FX;
  PrevPoint.Y := FPoints[Index - 1].FY;

  NextPoint.X := FPoints[Index + 1].FX;
  NextPoint.Y := FPoints[Index + 1].FY;

  IndexPoint.X := FPoints[Index].FX;
  IndexPoint.Y := FPoints[Index].FX;

  A := Vector2DGetFromTwoPoints(PrevPoint, NewPoint);
  B := Vector2DGetFromTwoPoints(PrevPoint, IndexPoint);

  B0 := Vektor2DMultiplyTwo(Vektor2DDivideWithFloat(B,1), B);
  H1 := Vector2DCrossProduct(A, B0);

  A := Vector2DGetFromTwoPoints(NextPoint, NewPoint);
  B := Vector2DGetFromTwoPoints(NextPoint, IndexPoint);

  B0 := Vektor2DMultiplyTwo(Vektor2DDivideWithFloat(B,1), B);
  H2 := Vector2DCrossProduct(A, B0);

  if (H1 < H2) then
    Result := False;
end;
Meine Funktionen zur Vektorrechnung sehen so aus:


Delphi-Quellcode:
function Vector2DCrossProduct(Vekt1, Vekt2 : TVector2D) : Double;
begin
  Result := Vekt1.X * Vekt2.Y - Vekt1.Y * Vekt2.X;
end;
Delphi-Quellcode:
function Vektor2DMultiplyTwo(Vekt1 : TVector2D; Vekt2 : TVector2D) : TVector2d;
begin
  Result.X := Vekt1.X + Vekt2.X;
  Result.Y := Vekt1.Y + Vekt2.Y;
end;

Delphi-Quellcode:
function Vektor2DDivideWithFloat(Vekt : TVector2D; Value : Double) : TVector2d;
begin
  Result.X := Value / Vekt.X;
  Result.Y := Value / Vekt.X;
end;
Delphi-Quellcode:
function Vector2DPointToOrt(P1 : TFloatPoint) : TVector2d;
begin
  Result.X := P1.X;
  Result.Y := P1.Y;
end;
Mein Vektor2D record ist so von euch übernommen:

Delphi-Quellcode:
  TVector2d = record
    procedure Assign(const newX, newY: Double);
    function Length: Double;
  case Boolean of
    False: (X: Double; Y: Double);
    True: (Values: Array[0..1] of Double);
  end;
Die Floatpoints sind:

Delphi-Quellcode:
  TFloatPoint = packed record
    X : Single;
    Y : Single;
  end;
Jetzt habe Ich leider immernoch nicht das gewünschte Verhalten, scheinbar sind H1 und H2 noch nicht wirklich das, was sie sein sollen. Ich Debugge nochmal ein bisschen und Poste hier meine Sourcen.
Die Leiter der Entwicklungsabteilung dreht total am Mausrad!
  Mit Zitat antworten Zitat