Author |
Topic: How to check if a point is inside a polygon? (Read 1539 times) |
|
knudvaneeden
Developer
member is offline


Posts: 32
|
 |
How to check if a point is inside a polygon?
« Thread started on: Jan 9th, 2014, 03:44am » |
|
Hi,
How to check if a point is inside a polygon? http://goo.gl/T6vhHS
with friendly greetings, Knud van Eeden
|
|
Logged
|
|
|
|
knudvaneeden
Developer
member is offline


Posts: 32
|
 |
Re: How to check if a point is inside a polygon?
« Reply #2 on: Jan 9th, 2014, 08:09am » |
|
Would it be possible to show a simplest example in BBC Basic using that API PtInRegion()?
Thanks
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: How to check if a point is inside a polygon?
« Reply #3 on: Jan 9th, 2014, 09:17am » |
|
on Jan 9th, 2014, 08:09am, knudvaneeden wrote:Would it be possible to show a simplest example in BBC Basic using that API PtInRegion()? |
|
Here's a simple program which changes the shape of the mouse pointer depending on whether it is inside or outside the polygon:
Code: DIM Poly{(4) x%, y%}
DATA 650, 680, 440, 470, 800, 230, 1300, 640, 930, 600
FOR I% = 0 TO 4
READ Poly{(I%)}.x%, Poly{(I%)}.y%
NEXT
MOVE Poly{(0)}.x%, Poly{(0)}.y%
FOR I% = 1 TO 4
DRAW Poly{(I%)}.x%, Poly{(I%)}.y%
NEXT
DRAW Poly{(0)}.x%, Poly{(0)}.y%
SYS "CreatePolygonRgn", Poly{(0)}, DIM(Poly{()},1)+1, 1 TO hrgn%
REPEAT
MOUSE X%, Y%, B%
SYS "PtInRegion", hrgn%, X%, Y% TO inside%
IF inside% MOUSE ON 137 ELSE MOUSE ON 0
WAIT 1
UNTIL FALSE Another use of the function can be found in the Rosetta Code example Honeycombs:
http://rosettacode.org/wiki/Honeycombs#BBC_BASIC
Richard.
|
|
Logged
|
|
|
|
|