PolToCar: Conversion of polar coordinates to 3d Cartesian coordinates

PolToCarR Documentation

Conversion of polar coordinates to 3d Cartesian coordinates

Description

The function uses basic trigonometric relationships to transform longitude/latitude coordinates on a sphere to xyz Cartesian coordinates.

Usage

PolToCar(x, ...)

## S4 method for signature 'matrix'
PolToCar(x, radius = authRadius, origin = c(0, 0, 0))

## S4 method for signature 'numeric'
PolToCar(x, radius = authRadius, origin = c(0, 0, 0))

## S4 method for signature 'data.frame'
PolToCar(x, radius = authRadius, origin = c(0, 0, 0), long = NULL, lat = NULL)

Arguments

x

(matrix, numeric, data.frame) A 2-column numeric matrix with the longitude/latitude data.

...

Arguments passed to class-specific methods.

radius

(numeric) The radius of the sphere. Defaults to the R2 radius of Earth (6371.007km).

origin

(numeric) Vector with length 3, the XYZ coordinates of the sphere center.

long

(character) If x is a data.frame, then the column used as longitudes.

lat

(character) If x is a data.frame, then the column used as latitudes.

Details

The authalic mean radius of Earth (6371.007 km) is used by this function as a default. The origin is c(0,0,0). The precision of these conversions is not exact (see example c(0,90) below), but should be considered acceptable when applied at a reasonable scale (e.g. for global analyses using data above 10e-6 meters of resolution).

Value

An xyz 3-column numeric matrix, data.frame or numeric, depending on the class of x.

Examples

longLat <- rbind(
  c(0,0),
  #note the precision here!
  c(0, 90),
  c(-45,12)
)
# matrix-method
xyz <- PolToCar(longLat)
# numeric-method
xyz2 <- PolToCar(longLat[1,])
# data.frame method
xyz3 <- PolToCar(as.data.frame(longLat))

adamkocsis/icosa documentation built on Aug. 20, 2024, 1:35 a.m.