Thank you for catching that, Boris. I'm surprised, given that there is no mention of sense of direction in the package documentation.
Scott Waichler > -----Original Message----- > From: Boris Steipe [mailto:boris.ste...@utoronto.ca] > Sent: Friday, April 18, 2014 3:49 PM > To: Waichler, Scott R; r-help@r-project.org > Subject: Re: [R] problem with pip2d() from ptinpoly > > Apparently it matters whether your polygon is defined clockwise or > counterclockwise. > > A point outside your triangle is recognized ... > > q2 <- matrix(c(594893.0,115435.0), ncol=2, byrow=T) pip2d(Vertices = > > verts, Queries = q2) > [1] 1 > > ... and defining the triangle in counterclockwise sense gives the expected > behaviour. > > v2 <- matrix(c(594891,115309,594891,117201,594444,117201), ncol=2, > > byrow=T) pip2d(Vertices = v2, Queries = query) > [1] 1 > > Cheers, > B. > > On 2014-04-18, at 6:00 PM, Waichler, Scott R wrote: > > > Hi, > > > > pip2d() doesn't seem to work correctly for me. I have a plot of a > triangle that a query point fits inside, but the point is defined as > outside the polygon by pip2d. > > > > library(ptinpoly) > > verts <- matrix(c(594891,115309,594444,117201,594891,117201), ncol=2, > > byrow=T) query <- matrix(c(594885.0,115435.0), ncol=2, byrow=T) > > pip2d(Vertices = verts, Queries = query) # result = -1 # contrary to > > -1 output of pip2d, plot shows point lies within triangle > > plot(c(594400, 595000), c(115000, 117500), type="n") polygon(verts, > > border="red") points(x=query[,1], y=query[,2], col="blue") > > > > Scott Waichler > > Pacific Northwest National Laboratory > > Richland, WA, USA ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.