closestpointonpolygon: computes the coordinates of the closest point on the border...

Description Usage Arguments Value Examples

View source: R/Distances.R

Description

computes the coordinates of the closest point on the border of a polygon to a point in the plane

Usage

1

Arguments

p

a numeric vector of length 2

.poly

a nx2 numeric matrix, representing a polygon. Each row of the matrix are the coordinates of a vertice of the polygon.

Value

the coordinates of the closest point on the polygon

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
 
zz<-function(){
.poly=matrix(sample(0:4,6,rep=T),3,2)[c(1:3,1),]
p<-sample(0:4,2,rep=T)
dd<-distpointtopoly(p,.poly)
plot(rbind(p,.poly),cex=.5,main=paste0("Distance: ", signif(dd,3)),
asp=1,xlim=range(cbind(p,.poly)),ylim=range(cbind(p,.poly)),xaxt='n',yaxt='n',xlab='',ylab='')
points(.poly,type="l",lwd=2)
cc<-rbind(p,closestpointonpolygon(p,.poly))
points(cc,col="red",cex=2)
points(cc,type="l",lty=3,col="red")
}

par(oma=c(0,0,0,0),mfrow=c(2,2))
set.seed(3);replicate(4,zz())

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