Sign in Join
Wiki copytemporary

Geometry in Pascal/de: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: Geometry in Pascal/de

OldNewLine
1+## Testen, ob ein Punkt in einem Polygon liegt
2+
3+``` pascal
4+// Die Funktion gibt den Wert True zurück, wenn der Punkt x,y innerhalb eines Polygons liegt.
5+// Die Funktion gibt den Wert False zurück, wenn der Punkt x,y nicht in einem Polygon liegt.
6+//
7+// Der Original C-Code: http://www.visibone.com/inpoly/inpoly.c.txt
8+//
9+// Übersetzng von C nach Pascal: Felipe Monteiro de Carvalho
10+//
11+// Lizenz: Public Domain
12+
13+function IsPointInPolygon(AX, AY: Integer; APolygon: array of TPoint): Boolean;
14+var
15+ xnew, ynew,
16+ xold, yold,
17+ x1, y1,
18+ x2, y2: Cardinal;
19+ i, npoints: Integer;
20+ inside: Integer = 0;
21+
22+begin
23+ Result := False;
24+
25+ npoints := Length(APolygon);
26+
27+ if (npoints < 3) then Exit;
28+
29+ xold := APolygon[npoints-1].X;
30+ yold := APolygon[npoints-1].Y;
31+
32+ for i := 0 to npoints - 1 do begin
33+ xnew := APolygon[i].X;
34+ ynew := APolygon[i].Y;
35+
36+ if (xnew > xold) then begin
37+ x1 := xold;
38+ x2 := xnew;
39+ y1 := yold;
40+ y2 := ynew;
41+ end else begin
42+ x1 := xnew;
43+ x2 := xold;
44+ y1 := ynew;
45+ y2 := yold;
46+ end;
47+
48+ if (((xnew < AX) = (AX <= xold)) and // Die Ecke ist am linken Ende "offen"
49+ ((AY - y1) * (x2 - x1) < (y2 - y1) * (AX - x1))) then
50+ begin
51+ inside := not inside;
52+ end;
53+
54+ xold := xnew;
55+ yold := ynew;
56+
57+ end;
58+
59+ Result := inside <> 0;
60+end;
61+```
62+
63+## Siehe auch
64+
65+- [A Point about Polygons](http://www.visibone.com/inpoly/) (Englisch)
66+
67+---
68+*From the Free Pascal wiki, page "Geometry in Pascal/de", as it stood on 2020-08-22 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history