minDist: Get the minimum geodesic distance between points

Description Usage Arguments Value Examples

View source: R/Geometry.R

Description

Get the minimum geodesic distance either between all points in a data.frame pairwise, or between all points in a data.frame and one target point.

Usage

1
minDist(df, point)

Arguments

df

A data.frame with columns x,y,z for cartesian or theta, phi for spherical colatitude and longitude respectively. The rows must correspond to points on the unit sphere. If this is a HPDataFrame or CMBDataFrame and coordinate columns are missing, then coordinates will be assigned based on HEALPix pixel indices.

point

An optional target point on the unit sphere in cartesian coordinates, in which case all distances are calculated between point and the points in df.

Value

If point is specified: the shortest distance from point to the points specified by the rows of df. If point is not specified: the shortest distance pairwise between points in df.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
## Using a CMBDataFrame with HEALPix coordinates only
cmbdf <- CMBDataFrame(nside = 1, spix = c(1,5,12), ordering = "ring")
plot(cmbdf, hp.boundaries = 1, col = "blue", size = 5)
p <- c(0,0,1)
minDist(cmbdf, p) # no need to have coordinates

## Using a HPDataFrame with HEALPix coordinates only
hp <- HPDataFrame(nside = 1, I = rep(0,3), spix = c(1,5,12) )
minDist(hp, p) # notice no need to have coordinates

## Using a data.frame with cartesian coordinates
coords(hp) <- "cartesian"
df <- data.frame(x = hp$x, y = hp$y, z = hp$z)
minDist(df, p)

## Using a data.frame with spherical coordinates
coords(hp) <- "spherical"
df <- data.frame(theta = hp$theta, phi = hp$phi)
minDist(df, p)

## min distance between points in cmdf
minDist(cmbdf)

rcosmo documentation built on Dec. 11, 2021, 9:29 a.m.