cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar

The "in polygon" function

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
mpb
mpb
Level VII

Re: The "in polygon" function

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

View solution in original post

2 REPLIES 2
mpb
mpb
Level VII

Re: The "in polygon" function

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

Re: The "in polygon" function

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