Skip to content

inout() in splancs working properly?

2 messages · Rainer Hurling, Roger Bivand

#
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
1 day later
#
Rainer:
On Sat, 2 Jun 2001, Rainer Hurling wrote:

            
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