polydistmat: Compute distance matrix for a list of polygons

Description Usage Arguments Value Examples

View source: R/Distances.R

Description

Compute distance matrix for a list of polygons

Usage

1
polydistmat(list.poly)

Arguments

list.poly

a list of nx2 numeric matrices

Value

a (n*(n-1)/2)x 3 matrix

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
zz<-function(){
list.poly=plyr::alply(cbind(rep(0:8,9),rep(0:8,each=9))[sample(81,4),],1,function(x){
cbind(x[1]+c(0,0,.5,.5,0),x[2]+c(0,.5,.5,0,0))})
gradients=cbind(c(0,1),c(1,0),c(1,1),c(1,-1))
par(mfrow=c(1,1),oma=c(0,0,0,0),mar=c(0.1,0.1,.1,0.1))
plot(do.call(rbind,list.poly),xlab="",yaxt="n",ylab="",cex=.1)
for(i in 1:length(list.poly)){.poly=list.poly[[i]]
points(.poly,type="l")
text(mean(.poly[,1]),mean(.poly[,2]),as.roman(i))
}
X=polydistmat(list.poly)
X<-cbind(X,floor(rank(X[,3])))
colorlink=topo.colors(2*max(X[,4]))[X[,4]]
for(i in 1:nrow(X)){
cc<-closestpointsontwopolygons(list.poly[[X[i,1]]],list.poly[[X[i,2]]])
points(cc,col=colorlink[i],type="l",lty=3)
text(mean(cc[,1]),mean(cc[,2]),signif(X[i,3],3))
}
colnames(X)<-c("polygon 1","polygon 2", "distance","col")
X[,1:3]}
set.seed(1);zz()

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