Registriert seit: 5. Mär 2007
Ort: Gwang-Yang-City
48 Beiträge
Delphi 2009 Enterprise
|
Re: Punkt in Dreieck?
26. Mai 2008, 04:16
@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
“C++ is an insult to the human brain.” [Niklaus Wirth]
2B OR NOT 2B (.. THAT IS FF)
|
|
Zitat
|