Description Usage Arguments Functions See Also Examples
A little tribe to help with euclidean distances calculations
1 2 3 4 5 6 7 8 9 10 11 12 13 | ed(x, y)
edi(x, y, r = 0.5)
ed_pw(x, y)
ed_nearest(x, y)
ed_furthest(x, y)
ed_calliper(x)
ed_minrad(x)
|
x, y |
coo_single, matrices or vectors of length 2 (when sensible) |
r |
|
ed
: calculates euclidean distance between two points
edi
: calculates intermediate position between two points
ed_pw
: calculates pairwise distances between two shapes
ed_nearest
: calculates closest point to y from x
ed_furthest
: calculates furthest point to y from x
ed_calliper
: find calliper (max pairwise ed) length
ed_minrad
: find minimal radius (min dist to centroid)
Other geometry:
geometry
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | x <- c(0, 0)
y <- c(1, 1)
ed(x, y) # sqrt(2)
edi(x, y, 0.25) # c(0.25, 0.25)
bot %>% dplyr::slice(1:2) %>% coo_sample(12) %>% dplyr::pull(coo) -> b
ed_pw(b[[1]], b[[2]])
# checking
purrr::map_dbl(1:12, ~ed(b[[1]][.x, ], b[[2]][.x, ]))
bot %>% pick(1) %>% ed_nearest(c(0, 0))
# nearest and furthest points
set.seed(2329) # for the sake of reproducibility when building the pkg
foo <- tibble::tibble(x=runif(5), y=runif(5))
z <- c(0.5, 0.5)
plot(foo, pch="")
text(foo, labels=1:5)
points(z[1], z[2], col="red", pch=20)
(nearest <- ed_nearest(foo, z))
segments(z[1], z[2],
as.numeric(foo[nearest$id, 1]), as.numeric(foo[nearest$id, 2]), col="blue")
(furthest <- ed_furthest(foo, z))
segments(z[1], z[2],
as.numeric(foo[furthest$id, 1]), as.numeric(foo[furthest$id, 2]), col="red")
(calli <- ed_calliper(foo))
segments(as.numeric(foo[calli$ids[1], 1]), as.numeric(foo[calli$ids[1], 2]),
as.numeric(foo[calli$ids[2], 1]), as.numeric(foo[calli$ids[2], 2]), col="green")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.