distpointtopoly: computes the distance between a point and a polygon

Description Usage Arguments Examples

View source: R/Distances.R

Description

computes the distance between a point and a polygon

Usage

1
distpointtopoly(p, .poly)

Arguments

p

a numeric vector of length 2

.poly

a n x2 numeric matrix, representing a polygon. Each row of the matrix are the coordinates of a verticeof the polygon.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
zz<-function(){
p<-sample(0:6,2,rep=T)
.poly<-matrix(sample(0:6,6,rep=T),3,2)[c(1:3,1),]
plot(rbind(.poly,p),
xlab="",ylab="",
cex=.2,main=paste0("Distance: ",signif(distpointtopoly(p,.poly),3)))
points(.poly,type='l')
points(x=p[1],y=p[2] ,col="red",cex=1)
points(closestpointonpolygon(p,.poly)[1],closestpointonpolygon(p,.poly)[2],col="red",cex=1)
points(rbind(p,closestpointonpolygon(p,.poly)),col="red",lty=3,type='l')}
par(mfrow=c(3,3),oma=c(0,0,1,0),mar=c(2,2.1,1,0.1))
set.seed(1);replicate(9,zz())

DanielBonnery/Strategy documentation built on Dec. 17, 2021, 4:03 p.m.