sl.gc.dist | R Documentation |
Compute great-circle distances between two or more points on a sphere. If coordinates for more than two points are provided, either distances between consecutive points, between the first and all other points, between specific pairs of points, or between all pairs of points are computed.
sl.gc.dist(lon = NULL, lat = NULL, x = NULL, y = NULL, z = NULL, Rsphere = 1, sequential = TRUE, distmat = FALSE, byrot = FALSE)
lon |
a vector of length |
lat |
a vector of length |
x |
a vector of length |
y |
a vector of length |
z |
a vector of length |
Rsphere |
a scalar value giving the radius of the sphere. Default is a unit sphere, that is, |
sequential |
a logical value specifying for the case that |
distmat |
a logical value specifying whether distances are computed between all pairs of points. In this case, the built-in function |
byrot |
a logical value specifying whether distances are computed by rotation, which can be slow. Default is |
As detailed in the function argument description above, this function can handle different types of inputs (lon,lat
versus x,y,z
; vectors versus 2-column matrices), use different approaches for the computation (rotation versus cartesian distance versus built-in dist
function), and compute distances between different sets of points (first against all others; subsequent pairs; all pairs).
Either a vector of length N-1
or M
(i.e., a scalar if N=2
or M=1
) with the great-circle distances between the points, or an MxM
matrix with all pairwise distances.
Helge Goessling
sl.cart.dist
sl.gc.dist(lon=c(0,30,90,0),lat=c(0,0,0,90))
## Should return:
## [1] 0.5235988 1.0471976 1.5707963
sl.gc.dist(lon=c(0,30,90,0),lat=c(0,0,0,90),sequential=FALSE)
## Should return:
## [1] 0.5235988 1.5707963 1.5707963
sl.gc.dist(lon=data.frame(lon1=c(10,25,30),lon2=c(20,35,0)),lat=data.frame(lat1=c(0,0,10),lon2=c(20,35,50)))
## Should return:
## [1] 0.3886629 0.6322375 0.8213473
sl.gc.dist(lon=c(0,30,90,0),lat=c(0,0,0,90),distmat=TRUE)
## Should return:
## 1 2 3 4
## 1 0.0000000 0.5235988 1.570796 1.570796
## 2 0.5235988 0.0000000 1.047198 1.570796
## 3 1.5707963 1.0471976 0.000000 1.570796
## 4 1.5707963 1.5707963 1.570796 0.000000
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.