Description Usage Arguments Examples
computes the distance between a point and a segment
1 | distpointtoseg(p, s)
|
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. |
1 2 3 4 5 6 7 8 9 10 11 | zz<-function(p){
s=matrix(c(0,3,0,0),2,2)
plot(s,type="l",xlim=c(-2,5),ylim=c(-2,2),
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")
text((closestpointonseg(p,s)[1]+p[1])/2,(closestpointonseg(p,s)[2]+p[2])/2,round(distpointtoseg(p,s),2))}
par(mfrow=c(3,3))
set.seed(1);replicate(9,zz(c(sample(-2:3,1),sample(-2:2,1))))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.