AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

3D Ray-Plane Intersection

Ein Thema von milos · begonnen am 29. Apr 2016 · letzter Beitrag vom 29. Apr 2016
 
Benutzerbild von milos
milos

Registriert seit: 14. Jul 2008
Ort: Bern (CH)
510 Beiträge
 
Delphi 11 Alexandria
 
#1

3D Ray-Plane Intersection

  Alt 29. Apr 2016, 09:10
Hallo,

ich habe hier im Forum diese funktion gefunden um den Schnittpunkt eines Graden und einer Form im 3D Raum zu berechnen.

Delphi-Quellcode:
function intersectPlaneLine(const planeA, planeB, planeC: TPoint3D;
  const lineA, lineB: TPoint3D): TPoint3D;
var
  AB, AC: TPoint3D;
  planeNormal: TPoint3D;
  DE: TPoint3D;
  d, t: Single;
  divisor: Single;
begin
  // 1a
  AB := Point3D(planeB.X - planeA.X, planeB.Y - planeA.Y, planeB.Z - planeA.Z);
  AC := Point3D(planeC.X - planeA.X, planeC.Y - planeA.Y, planeC.Z - planeA.Z);
  // 1b
  // Kreuzprodukt (siehe Wikipedia, sofern nicht verständlich)
  planeNormal := Point3D(AB.Y*AC.Z - AB.Z*AC.Y, AB.Z*AC.X - AB.X*AC.Z, AB.X*AC.Y - AB.Y*AC.X);
  d := planeA.X*planeNormal.X + planeA.Y*planeNormal.Y + planeA.Z*planeNormal.Z;
  // 2a
  DE := Point3D(lineB.X - lineA.X, lineB.Y - lineA.Y, lineB.Z - lineA.Z);
  // 3
  divisor := planeNormal.X*DE.X + planeNormal.Y*DE.Y + planeNormal.Z*DE.Z;
  if divisor = 0 then
    // die Gerade steht 90° zur Ebenennormale --> sie ist parallel
    // Lösung: keine oder unendlich viele - wir liefern niks
    Result := Point3D(0, 0, 0)
  else
  begin
    t := (d - planeNormal.X*lineA.X - planeNormal.Y*lineA.Y - planeNormal.Z*lineA.Z) / divisor;
    // 4
    Result := Point3D(lineA.X + t*DE.X, lineA.Y + t*DE.Y, lineA.Z + t*DE.Z);
  end;
end;
Diese funktioniert einwandfrei, jedoch gibt es mir auch Werte aus wenn kein Schnittpunkt dazwischen liegt.
z.B. das:

Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var
  LPoint : TPoint3D;
begin
  LPoint := intersectPlaneLine(
    Point3d(100,100,100),
    Point3d(200,200,100),
    Point3d(200,100,100),
    Point3d(0,0,-1000),
    Point3d(0,0,1000)
  )
end;
bekomme ich Point3D(0,0,100) zurück obwohl da gar nichts liegen sollte? Komisch ist das die Z Achse korrekt ist. Wo ist da der Wurm drin?

MfG
Milos
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 15:24 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