[R] problem with pip2d() from ptinpoly
boris.steipe at utoronto.ca
Sat Apr 19 00:48:45 CEST 2014
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)
... 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)
On 2014-04-18, at 6:00 PM, Waichler, Scott R wrote:
> 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.
> 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 at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help