Description Usage Arguments Value Examples
computes the coordinates of the closest point on the border of a polygon to a point in the plane
1 | closestpointonpolygon(p, .poly)
|
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. |
the coordinates of the closest point on the polygon
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())
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.