polysmalldistmat: 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
2
3
4
5
6
polysmalldistmat(
  list.poly,
  delta,
  gradients = apply(cbind(c(0, 1), c(1, 0), c(1, 1), c(1, -1)), 2, function(x) {    
    x/(sqrt(sum(x^2))) })
)

Arguments

list.poly

a list of nx2 numeric matrices

delta

a positive number

gradients

a 2x n matrix each column representing a vector.

Value

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
zz<-function(delta){
list.poly=plyr::alply(cbind(rep(0:8,9),rep(0:8,each=9))[sample(81,20),],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,1,0),mar=c(0.1,0.1,1,0.1))
plot(do.call(rbind,list.poly),xlab="",yaxt="n",ylab="",cex=.1,main=paste0("Match polygons distant less than ",delta))
for(.poly in list.poly){points(.poly,type="l")}
X=polysmalldistmat(list.poly,delta)
for(i in 1:nrow(X)){
points(closestpointsontwopolygons(list.poly[[X[i,1]]],list.poly[[X[i,2]]]),col="red",type="l",lty=3)
}}
set.seed(1);zz(.5)
set.seed(1);zz(1)
set.seed(1);zz(2)

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