distance_to_line {tigers} | R Documentation |
Distance to Line
Description
These functions calculate the shortest distances from a set of points to a line (in Euclidean coordinates) or an arc (in angular coordinates).
dtl
and dta
are aliases to distance_to_line
and
distance_to_arc
, respectively.
Usage
distance_to_line(x, y = NULL, x0, y0, x1, y1,
alpha = NULL, beta = NULL)
dtl(x, y = NULL, x0, y0, x1, y1, alpha = NULL, beta = NULL)
distance_to_arc(x, y = NULL, x0, y0, x1, y1, prec = 0.001)
dta(x, y = NULL, x0, y0, x1, y1, prec = 0.001)
Arguments
x , y |
the coordinates of the points given in the usual way in R. |
x0 , y0 , x1 , y1 |
the coordinates of two points defining the line
similar to |
alpha , beta |
alternatively to the previous arguments, the
parameters of the line ( |
prec |
the precision of the estimated distances (see details). |
Details
distance_to_line
uses Euclidean geometry (see references). The
coordinates can be in any units.
distance_to_arc
uses distances along arcs on the (Earth)
sphere. The coordinates must be in decimal degrees. The calculations
are done by iterations using intervals of decreasing lengths along the
arc. The iterations are stopped when the required precision is reached
(see argument prec
).
Value
a numeric vector giving the distances; distance_to_line
returns
them in the same unit than the input data; distance_to_arc
returns them in kilometres (km).
Author(s)
Emmanuel Paradis
References
https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line
See Also
great_circle_line
, geoTrans
,
geod
Examples
## distance from the topleft corner of the unity square to the diagonal:
(d <- dtl(matrix(c(1, 0), , 2), NULL, 0, 0, 1, 1))
all.equal(d, sqrt(2)/2)
## see also ?great_circle_line
x <- y <- 0:10/10
dta(x, y, 0, 0, 1, 1)