closestpointsontwosegments_n: returns a list of one or more pair of points, one on each of...

Description Usage Arguments Value Examples

View source: R/Distances.R

Description

returns a list of one or more pair of points, one on each of two segments, with minimal distance

Usage

1

Arguments

s1

a 2x2 numeric matrix, representing a segment. Each row of the matrix are the coordinates of a extreme point of the segment.

s2

a 2x2 numeric matrix, representing a segment. Each row of the matrix are the coordinates of a extreme point of the segment.

Value

a list of 2x2 numeric matrices, representing a segment.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
zz<-function(){
s1=matrix(sample(0:4,4,rep=T),2,2)
s2=matrix(sample(0:4,4,rep=T),2,2)
s<-rbind(s1,s2)
dd<-distsegmenttosegment(s1,s2)
plot(s,cex=.5,main=paste0("Distance: ", signif(dd,3)),asp=1,xlim=range(s),ylim=range(s),xaxt='n',yaxt='n',xlab='',ylab='')
points(s1,type="l",lwd=2)
points(s2,type="l",lwd=2)
cc<-closestpointsontwosegments_n(s1,s2)
for(ccc in cc){points(ccc ,col="red",cex=2)
points(ccc,type="l",col="red",lty=3)}
}

par(oma=c(0,0,0,0),mfrow=c(3,3))
set.seed(3);replicate(9,zz())
closestpointsontwosegments_n(matrix(c(0,3,0,0),2,2),matrix(c(1,2,0,0),2,2))

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