I have a problem with function 'inout()' in package 'splancs' on CRAN-R Version 1.2.3 under FreeBSD4.3-STABLE. The following script produces and draws points and a polygon-surrounded area. Repeating the same script many times shows, that points on the polygon-line often, but not always, are outside of the polygon-area. library(splancs) # dataset with polygon (convex hull) ds1 <- as.points(rnorm(10),rnorm(10)) ds1.poly <- ds1[chull(ds1),] # plot area within convex hull plot(ds1, type="n") polymap(ds1.poly, border="lightblue", col="lightblue", lwd=1) # Next dataset in and out of first one ds2 <- as.points(rnorm(100),rnorm(100)) points(ds2[inout(ds2,ds1.poly),], col="green", pch=20) points(ds2[!inout(ds2,ds1.poly),], col="orange", pch=20) points(ds1[inout(ds1,ds1.poly),], col="black", pch=20) points(ds1[!inout(ds1,ds1.poly),], col="red", pch=20) If points lay on the polygon-line, inout() tells sometimes they are inside (black points), sometimes outside (red points) of the surrounded (here ligthblue) area. Same with another dataset, testing against the given polygon. Points inside are shown in green, outside in orange color. Some of the orange points must be green points? Is my understanding of function inout() correct? I am looking for a function, that gives all points inside the area, including points laying on the polygon-line, as 'TRUE' or 'inside'. I had a look at your source code at 'splancs/src/ipippa.f', but had not been able to resolve my problem here. (Perhaps variable 'iwind' is not modified correctly at all situations?) It would be very nice, if you could give me a hint what I'm doing wrong and how to solve my problem. Excuse me for my weaky english. Many thanks in advance. Rainer Hurling -- Rainer Hurling, Ass. d. Fd. email: rhurlin at gwdg.de Institut fuer Forstzoologie und Waldschutz http://www.gwdg.de/~rhurlin Georg-August Universitaet Goettingen office: 0551 39-2291 Buesgenweg 3, D-37077 Goettingen, GERMANY fax: 0551 39-2089 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Rainer: On Sat, 2 Jun 2001, Rainer Hurling wrote:> I have a problem with function 'inout()' in package 'splancs' on CRAN-R > Version 1.2.3 under FreeBSD4.3-STABLE. > > The following script produces and draws points and a polygon-surrounded > area. Repeating the same script many times shows, that points on the > polygon-line often, but not always, are outside of the polygon-area. > > If points lay on the polygon-line, inout() tells sometimes they are > inside (black points), sometimes outside (red points) of the surrounded > (here ligthblue) area. > > Is my understanding of function inout() correct? I am looking for a > function, that gives all points inside the area, including points laying > on the polygon-line, as 'TRUE' or 'inside'. >Yes and no. Computational geometry is a black art, and point-in-polygon algorithms usually return the answer to whether the point is inside the polygon or not (inside meaning inside the boundary). Some algorithms will also tell you whether the point is on the (vanishingly thin) boundary itself. In your trial case, the vertices of the convex hull are both in the set of points being tested and are actual boundary vertices, a very untypical situation in empirical settings. If you "jittered" them so that they didn't coincide exactly in their binary representation, the algorithm would answer happily either yes or no - as it is, it says that boundary points may be either in or not, depending (somewhat) on where your vertex is around the boundary. There is no general acceptance for points on boundaries being either inside or outside, but in the next splancs release, the documentation will be changed to reflect this issue, and I may try some alternative algorithms to give three replies, and the user the choice of including points on boundaries. Hope this helps, Roger -- Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Breiviksveien 40, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93 e-mail: Roger.Bivand at nhh.no and: Department of Geography and Regional Development, University of Gdansk, al. Mar. J. Pilsudskiego 46, PL-81 378 Gdynia, Poland. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Roger, sorry for not recognizing you as the author of the port. Roger Bivand wrote:> > Rainer: > > Thankyou for your very helpful report, showing clearly and replicably what > the problem is: sometimes points on the convex hull are included, > sometimes not. I agree that the issue is in ipippa.f, but am not too sure > why (yet). I am working on a revision of splancs at the moment - can I use > you to help test out this issue? >Of course you can. I will test it with my datasets.> (Barry - is this so far back in the past that you don't have Ken > McElvain's C-code? Are we dealing with: > > http://jedi.ks.uiuc.edu/~johns/raytracer/rtn/rtnv3n4.html#art23 > > Does the original comment: > > ">A remark: The whichquad function is not perfect. It doesn't handle > >the boundary cases right (but as I said, that's only a problem > >if the point lies on the polygon)." > > still hold?) > > Thanks again, > > Roger > > -- > Roger Bivand > Economic Geography Section, Department of Economics, Norwegian School of > Economics and Business Administration, Breiviksveien 40, N-5045 Bergen, > Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93 > e-mail: Roger.Bivand at nhh.no > and: Department of Geography and Regional Development, University of > Gdansk, al. Mar. J. Pilsudskiego 46, PL-81 378 Gdynia, Poland.Rainer -- Rainer Hurling, Ass. d. Fd. email: rhurlin at gwdg.de Institut fuer Forstzoologie und Waldschutz http://www.gwdg.de/~rhurlin Georg-August Universitaet Goettingen office: 0551 39-2291 Buesgenweg 3, D-37077 Goettingen, GERMANY fax: 0551 39-2089 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._