closestpointsontwosegments: computes the coordinates of the closest point on a segment to...

Description Usage Arguments Examples

View source: R/Distances.R

Description

computes the coordinates of the closest point on a segment to a point in the plane

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.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
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(s1,s2)
points(cc ,col="red",cex=2)
points(cc,type="l",col="red",lty=3)
}

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

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