Thema: Delphi klick in parallelogramm

Einzelnen Beitrag anzeigen

blackfin
(Gast)

n/a Beiträge
 
#2

Re: klick in parallelogramm

  Alt 6. Mai 2010, 12:29
Ungetestet:

Eigentlich müsste dazu ja folgende Funktion aus GLScene funktionieren.
Die Eckpunkte übergibst du einfach als xp (X-Koordinaten der Eckpunkte) und yp (Y-Koordinaten der Eckpunkte).
Und den Klick-Punkt als x,y. Die Reihenfolge der Eckpunkte ist wichtig. Übergib sie so, wie das Parallelogramm auch gezeichnet wird.
Obwohl hier singles verwendet werden, müsste es ja mit Integern auch gehen.
Aber wie gesagt, ungetestet

Delphi-Quellcode:
// PointInPolygon
//
function PointInPolygon(var xp, yp : array of Single; x, y: Single) : Boolean;
// The code below is from Wm. Randolph Franklin <wrf@ecse.rpi.edu>
// with some minor modifications for speed. It returns 1 for strictly
// interior points, 0 for strictly exterior, and 0 or 1 for points on
// the boundary.
var
   I, J: Integer;
begin
   Result:=False;
   if High(XP)=High(YP) then begin
      J:=High(XP);
      for I:=0 to High(XP) do begin
         if ((((YP[I]<=Y) and (Y<YP[J])) or ((YP[J]<=Y) and (Y<YP[I])) )
             and (X<(XP[J]-XP[I])*(Y-YP[I])/(YP[J]-YP[I])+XP[I])) then
            Result:=not Result;
         J:=I;
      end;
   end;
end;
  Mit Zitat antworten Zitat