Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- The "in polygon" function

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Dec 10, 2011 10:47 AM
(651 views)

I've been having problems getting a script to work in JMP 8 in which I need to determine whether a point is inside or outside a polygon. I've now stripped the problem down to a simple example that illustrates what's happening, and include it below. It initially looks fine, but if I click around the coordinates {75, 75}, the script reports that the point is still inside the polygon - which it isn't. The vertices of the polygon don't cross over themselves in terms of the order in which they're defined - which was my first suspicion - so what, if anything, have I missed? Whatever it is, JMP 9 appears to have allowed for it, because it works as I'd expect it to there. It needs to run in either, however, so I'm wondering whether I'll need to find an alternative to the "in polygon" function. I can do it, but I shan't bother if I've just made a simple error. Here's the script:

// Polygon;

XA = **[****0**, -**50**, -**50**, **50**, **50]**;

YA = **[****100**, **50**, -**50**, -**50**, **50]**;

// Initial point on graph;

xp = **0**; yp = **0**;

gb = Graph Box**(**FrameSize**(****400**, **400)**, XScale**(**-**110**, **110)**, yScale**(**-**110**, **110)**,

mousetrap**({}**, xp = x; yp = y**)**,

transparency**(0.2)**;

for**(**i=-**100**, i<=**100**, i=i+**10**, hline**(**i**)**; vline**(**i**))**;

marker size**(5)**; fill color**(**"blue"**)**; polygon**(**XA, YA**)**;

transparency**(0.99)**; marker**(0**, **{**xp, yp**})**;

text**(**center justified, **{**xp, yp+**5}**, if**(**in polygon**(**xp, yp, XA, YA**)**, "In", "Out"**))**

**)**;

nw = new window**(**"Demo", gb**)**;

Many thanks for any help

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Solution

I repeated the first point (0,100) at the end of the polygon list of points and it worked in JMP 8.

2 REPLIES

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

I repeated the first point (0,100) at the end of the polygon list of points and it worked in JMP 8.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Dec 10, 2011 2:36 PM
(544 views)

Yes, of course - I should have tried that. Problem solved - many thanks!