Geometry in Pascal/de: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | - | ||
| 2 | - | ||
| 3 | - | ||
| 4 | - | ||
| 5 | - | ||
| 6 | - | ||
| 7 | - | ||
| 8 | - | ||
| 9 | - | ||
| 10 | - | ||
| 11 | - | ||
| 12 | - | ||
| 13 | - | ||
| 14 | - | ||
| 15 | - | ||
| 16 | - | ||
| 17 | - | ||
| 18 | - | ||
| 19 | - | ||
| 20 | - | ||
| 21 | - | ||
| 22 | - | ||
| 23 | - | ||
| 24 | - | ||
| 25 | - | ||
| 26 | - | ||
| 27 | - | ||
| 28 | - | ||
| 29 | - | ||
| 30 | - | ||
| 31 | - | ||
| 32 | - | ||
| 33 | - | ||
| 34 | - | ||
| 1 | + | ## Contents | |
| 35 | 2 | ||
| 36 | - | ||
| 37 | - | ||
| 38 | - | ||
| 39 | - | ||
| 40 | - | ||
| 41 | - | ||
| 42 | - | ||
| 43 | - | ||
| 44 | - | ||
| 45 | - | ||
| 46 | - | ||
| 3 | + | * 1 Testen, ob ein Punkt in einem Polygon liegt | |
| 4 | + | * 2 Siehe auch | |
| 47 | 5 | ||
| 48 | - | ||
| 49 | - | ||
| 6 | + | ## Testen, ob ein Punkt in einem Polygon liegt | |
| 7 | + | ``` | |
| 8 | + | // Die Funktion gibt den Wert True zurück, wenn der Punkt x,y innerhalb eines Polygons liegt. | |
| 9 | + | // Die Funktion gibt den Wert False zurück, wenn der Punkt x,y nicht in einem Polygon liegt. | |
| 10 | + | // | |
| 11 | + | // Der Original C-Code: http://www.visibone.com/inpoly/inpoly.c.txt | |
| 12 | + | // | |
| 13 | + | // Übersetzng von C nach Pascal: Felipe Monteiro de Carvalho | |
| 14 | + | // | |
| 15 | + | // Lizenz: Public Domain | |
| 16 | + | ||
| 17 | + | function IsPointInPolygon(AX, AY: Integer; APolygon: array of TPoint): Boolean; | |
| 18 | + | var | |
| 19 | + | xnew, ynew, | |
| 20 | + | xold, yold, | |
| 21 | + | x1, y1, | |
| 22 | + | x2, y2: Cardinal; | |
| 23 | + | i, npoints: Integer; | |
| 24 | + | inside: Integer = 0; | |
| 25 | + | ||
| 50 | 26 | begin | |
| 51 | - | ||
| 27 | + | Result := False; | |
| 28 | + | ||
| 29 | + | npoints := Length(APolygon); | |
| 30 | + | ||
| 31 | + | if (npoints < 3) then Exit; | |
| 32 | + | ||
| 33 | + | xold := APolygon[npoints-1].X; | |
| 34 | + | yold := APolygon[npoints-1].Y; | |
| 35 | + | ||
| 36 | + | for i := 0 to npoints - 1 do begin | |
| 37 | + | xnew := APolygon[i].X; | |
| 38 | + | ynew := APolygon[i].Y; | |
| 39 | + | ||
| 40 | + | if (xnew > xold) then begin | |
| 41 | + | x1 := xold; | |
| 42 | + | x2 := xnew; | |
| 43 | + | y1 := yold; | |
| 44 | + | y2 := ynew; | |
| 45 | + | end else begin | |
| 46 | + | x1 := xnew; | |
| 47 | + | x2 := xold; | |
| 48 | + | y1 := ynew; | |
| 49 | + | y2 := yold; | |
| 50 | + | end; | |
| 51 | + | ||
| 52 | + | if (((xnew < AX) = (AX <= xold)) and // Die Ecke ist am linken Ende "offen" | |
| 53 | + | ((AY - y1) * (x2 - x1) < (y2 - y1) * (AX - x1))) then | |
| 54 | + | begin | |
| 55 | + | inside := not inside; | |
| 56 | + | end; | |
| 57 | + | ||
| 58 | + | xold := xnew; | |
| 59 | + | yold := ynew; | |
| 60 | + | ||
| 61 | + | end; | |
| 62 | + | ||
| 63 | + | Result := inside <> 0; | |
| 52 | 64 | end; | |
| 53 | - | ||
| 54 | - | ||
| 55 | - | ||
| 56 | - | ||
| 57 | - | ||
| 58 | - | ||
| 59 | - | ||
| 60 | - | ||
| 61 | 65 | ``` | |
| 62 | 66 | ||
| 63 | 67 | ## Siehe auch | |
| 64 | 68 | ||
| 65 | - | ||
| 69 | + | * [A Point about Polygons](<http://www.visibone.com/inpoly/>) (Englisch) | |
| 66 | 70 | ||
| 67 | 71 | --- | |
| 68 | - | ||
| 72 | + | *From the Free Pascal wiki, page "Geometry in Pascal/de", as the Internet Archive kept it on 2023-06-04. 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).* |
