BBC BASIC for Windows
« How to check if a point is inside a polygon? »

Welcome Guest. Please Login or Register.
Apr 6th, 2018, 12:01am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: How to check if a point is inside a polygon?  (Read 1540 times)
knudvaneeden
Developer

member is offline

Avatar




Homepage PM


Posts: 32
xx 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

User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: How to check if a point is inside a polygon?
« Reply #1 on: Jan 9th, 2014, 03:52am »

on Jan 9th, 2014, 03:44am, knudvaneeden wrote:
How to check if a point is inside a polygon?

Whenever I've wanted to do that I've used the CreatePolygonRegion and PtInRegion Windows API functions:

http://msdn.microsoft.com/en-us/library/windows/desktop/dd183512.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/dd162883.aspx

I don't know how efficient that approach is, but it's simple to use and has always been fast enough for my purposes (I make heavy use of it in my Quadrant Editor application which is part of my suite of Colour Recovery programs).

Richard.
User IP Logged

knudvaneeden
Developer

member is offline

Avatar




Homepage PM


Posts: 32
xx 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
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx 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.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls