Sign in Join
Wiki copytemporary

Geometry in Pascal/fr: what changed

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

Title: Geometry in Pascal/fr

OldNewLine
1+## Contrôle si un point Checking est à l'intérieur d'un polygone (version basée sur les entiers)
2+
3+``` pascal
4+// La fonction retourne True si le point x,y est dans le polygone, ou False sinon
5+//
6+// Original C code: http://www.visibone.com/inpoly/inpoly.c.txt
7+//
8+// Traduit du langage C par Felipe Monteiro de Carvalho
9+//
10+// License: Public Domain
11+function IsPointInPolygon(AX, AY: Integer; APolygon: array of TPoint): Boolean;
12+var
13+ xnew, ynew: Cardinal;
14+ xold,yold: Cardinal;
15+ x1,y1: Cardinal;
16+ x2,y2: Cardinal;
17+ i, npoints: Integer;
18+ inside: Integer = 0;
19+begin
20+ Result := False;
21+ npoints := Length(APolygon);
22+ if (npoints < 3) then Exit;
23+ xold := APolygon[npoints-1].X;
24+ yold := APolygon[npoints-1].Y;
25+ for i := 0 to npoints - 1 do
26+ begin
27+ xnew := APolygon[i].X;
28+ ynew := APolygon[i].Y;
29+ if (xnew > xold) then
30+ begin
31+ x1:=xold;
32+ x2:=xnew;
33+ y1:=yold;
34+ y2:=ynew;
35+ end
36+ else
37+ begin
38+ x1:=xnew;
39+ x2:=xold;
40+ y1:=ynew;
41+ y2:=yold;
42+ end;
43+ if (((xnew < AX) = (AX <= xold)) // bord "ouvert" à l'extrémité gauche
44+ and ((AY-y1)*(x2-x1) < (y2-y1)*(AX-x1))) then
45+ begin
46+ inside := not inside;
47+ end;
48+ xold:=xnew;
49+ yold:=ynew;
50+ end;
51+ Result := inside <> 0;
52+end;
53+```
54+
55+## Voir aussi
56+
57+- [Un point sur les polygones](http://www.visibone.com/inpoly/)
58+
59+---
60+*From the Free Pascal wiki, page "Geometry in Pascal/fr", as it stood on 2020-02-16 after a change by Trev, 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