Learn R Programming

swfscMisc (version 1.6.5)

perpDist: Perpendicular Distance

Description

Calculate the perpendicular distance of a matrix of points to a line.

Usage

perpDist(pts, line)

Arguments

pts

two column matrix of points.

line

either a 2x2 matrix of points defining line or two element vector giving intercept and slope of line.

Author

Eric Archer eric.archer@noaa.gov

Examples

Run this code
ran.pts <- matrix(runif(10), ncol = 2)
x <- perpDist(ran.pts, c(0, 1))
x

plot.new()
plot.window(xlim = c(0, 1), ylim = c(0, 1), asp = 1)
abline(a = 0, b = 1)
points(ran.pts[, 1], ran.pts[, 2])
segments(ran.pts[, 1], ran.pts[, 2], x[, 1], x[, 2], lty = "dashed")
points(x[, 1], x[, 2], col = "red")
axis(1, pos = 0)
axis(2, pos = 0)

Run the code above in your browser using DataLab