Rev 8553 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{inSide}\alias{inSide}%- Also NEED an `\alias' for EACH other topic documented here.\title{Are points inside boundary?}\description{Assesses whether points are inside a boundary. The boundary must enclose thedomain, but may include islands.}\usage{inSide(bnd,x,y,xname=NULL,yname=NULL)}%- maybe also `usage' for other objects documented here.\arguments{\item{bnd}{This should have two equal length columns with names matching whatever issupplied in \code{x} and \code{y}. This may contain several sections of boundary separated by\code{NA}. Alternatively \code{bnd} may be a list, each element of whichcontains 2 columns named as above.See below for details.}\item{x}{x co-ordinates of points to be tested.}\item{y}{y co-ordinates of points to be tested.}\item{xname}{name of variable in \code{bnd} that \code{x} relates to. Defaults to name of variable supplied as \code{x}.}\item{yname}{name of variable in \code{bnd} that \code{y} relates to. Defaults to name of variable supplied as \code{y}.}}\details{Segments of boundary are separated by \code{NA}s, or are in separate list elements.The boundary co-ordinates are taken to define nodes which are joined by straight line segments inorder to create the boundary. Each segment is assumed todefine a closed loop, and the last point in a segment will be assumed to bejoined to the first. Loops must not intersect (no test is made forthis).The method used is to count how many times a line, in the y-direction from apoint, crosses a boundary segment. An odd number of crossings defines aninterior point. Hence in geographic applications it would be usual to havean outer boundary loop, possibly with some inner `islands' completelyenclosed in the outer loop.The routine calls compiled C code and operates by an exhaustive search foreach point in \code{x, y}.}\value{ The function returns a logical array of the same dimension as \code{x} and\code{y}. \code{TRUE} indicates that the corresponding \code{x, y} point liesinside the boundary.}\author{ Simon N. Wood \email{simon.wood@r-project.org}}\examples{require(mgcv)m <- 300;n <- 150xm <- seq(-1,4,length=m);yn <- seq(-1,1,length=n)x <- rep(xm,n);y <- rep(yn,rep(m,n))er <- matrix(fs.test(x,y),m,n)bnd <- fs.boundary()in.bnd <- inSide(bnd,x,y)plot(x,y,col=as.numeric(in.bnd)+1,pch=".")lines(bnd$x,bnd$y,col=3)points(x,y,col=as.numeric(in.bnd)+1,pch=".")## check boundary details ...plot(x,y,col=as.numeric(in.bnd)+1,pch=".",ylim=c(-1,0),xlim=c(3,3.5))lines(bnd$x,bnd$y,col=3)points(x,y,col=as.numeric(in.bnd)+1,pch=".")## alternatively, give the names of x and yd <- data.frame(x, y); rm(x, y)in.bnd2 <- inSide(bnd, d$x, d$y, xname="x", yname="y")all.equal(in.bnd, in.bnd2)}\keyword{models} \keyword{smooth} \keyword{regression}%-- one or more ..