## Not run: 
# plot(c(0, 1), c(0, 1), type = "n", asp=1, 
#      xlab = "", ylab = "", main = "Segment Distances")
# grid()
# for (i in 1:20) {
#     s1 <- matrix(runif(4), 2, 2)
#     s2 <- matrix(runif(4), 2, 2)
#     lines(s1[, 1], s1[, 2], col = "red")
#     lines(s2[, 1], s2[, 2], col = "darkred")
#     S <- segm_distance(s1[1,], s1[2,], s2[1,], s2[2,])
#     S$d
#     points(c(S$p[1], S$q[1]), c(S$p[2], S$q[2]), pch=20, col="navy")
#     lines(c(S$p[1], S$q[1]), c(S$p[2], S$q[2]), col="gray")
# }## End(Not run)
Run the code above in your browser using DataLab