
Conversion of polar coordinates to 3d Cartesian coordinates
Source:R/utils-conversion.R
PolToCar.RdThe function uses basic trigonometric relationships to transform longitude/latitude coordinates on a sphere to xyz Cartesian coordinates.
Usage
PolToCar(x, ...)
# S4 method for class 'matrix'
PolToCar(x, radius = authRadius, origin = c(0, 0, 0))
# S4 method for class 'numeric'
PolToCar(x, radius = authRadius, origin = c(0, 0, 0))
# S4 method for class 'data.frame'
PolToCar(x, radius = authRadius, origin = c(0, 0, 0), long = NULL, lat = NULL)Arguments
- x
(
matrix,numeric,data.frame) A 2-columnnumericmatrix 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 length3, the XYZ coordinates of the sphere center.- long
(
character) Ifxis adata.frame, then the column used as longitudes.- lat
(
character) Ifxis adata.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).
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))