closestpointonseg: 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

p

a numeric vector of length 2

s

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
zz<-function(p){
s=matrix(c(0,1,0,0),2,2)
plot(s,type="l",xlim=c(-.5,1.5),
xlab="",ylab="",
xaxt='n',yaxt='n')
points(x=p[1],y=p[2] ,col="red",cex=.5)
points(closestpointonseg(p,s)[1],closestpointonseg(p,s)[2],col="red",cex=.5)
segments(x0 = p[1],y0=p[2],x1=closestpointonseg(p,s)[1],y1=closestpointonseg(p,s)[2],col="red")}
par(mfrow=c(3,3))
set.seed(1);replicate(9,zz(c(runif(1,-.5,1.5),runif(1,-1,1))))

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