distance | R Documentation |
Calculate distance between points on planar surface
distance(x, y, xref, yref, along = FALSE)
x |
vector with x-coordinate(s) of point(s) |
y |
ditto for y |
xref |
single x coordinate of reference point |
yref |
ditto for y |
along |
Logical: Should distances be computed along vector |
The function is quite simple: sqrt((xref - x)^2 + (yref - y)^2)
vector with the distances
Berry Boessenkool, berry-b@gmx.de, 2012
nndist
in the package spatstat.geom
for distance to nearest neighbour
A <- c(3, 9,-1)
B <- c(7, -2, 4)
plot(A,B)
text(A,B, paste0("P",1:3), adj=1.1)
points(3,5, col=2, pch=16)
segments(3,5, A,B)
distance(A,B, 3,5)
text(c(3.2,6,1), c(6,1,4), round(distance(A,B, 3,5),2) )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.