Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Neuen Beitrag zur Code-Library hinzufügen (https://www.delphipraxis.net/33-neuen-beitrag-zur-code-library-hinzufuegen/)
-   -   Delphi Punkt in Dreieck? (https://www.delphipraxis.net/114455-punkt-dreieck.html)

LoCrux 26. Mai 2008 03:16

Re: Punkt in Dreieck?
 
@All,

will Eure Leistung auch nicht schmaelern. Aber es geht auch allgemeinguelting ohne Division.

Delphi-Quellcode:

type

  TSimplePoint = record
                   x,y : Double;
                 end;

.
.
.

function bSubPoints(p1,p2:TSimplePoint):TSimplePoint;
begin
  result.x := p1.x-p2.x;
  result.y := p1.y-p2.y;
end;

function bPointInTriangle(Tri1,Tri2,Tri3,APnt:TSimplePoint):Boolean;
var
  a,b,c   : Double;
  T1,T2,T3 : TSimplePoint;
begin
  // Zwillinger - Standard Mathematical Tables and Formulae, 31st Ed [CRC Press 2003]
  // Kapitel 4 Geometrie Abs 4.5 Polygone
  // FIRST PLACE ANY POINT TO ZERO(0,0) AND MOVE THE OTHERS RESPECTIVLY --> HERE Tri1
  T1 := bSubPoints(Tri2,Tri1);
  T2 := bSubPoints(Tri3,Tri1);
  T3 := bSubPoints(APnt,Tri1);
  // COMPUTE
  a := (T1.x*T2.y)-(T2.x*T1.y);
  b := (T1.x*T3.y)-(T3.x*T1.y);
  c := (T2.x*T3.y)-(T3.x*T2.y);
  // RESULT
  result := Boolean( ((a*b)>0) AND ((a*c)<0) AND ((a*(a-b+c))>0) ); // if TRUE then POINT IS IN THE TRIANGLE
end;
eidts: falsche fehler


Alle Zeitangaben in WEZ +1. Es ist jetzt 00:34 Uhr.
Seite 2 von 2     12   

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz