Conversion of polar coordinates to 3d Cartesian coordinates
Source:R/utils-conversion.R
PolToCar.Rd
The function uses basic trigonometric relationships to transform longitude/latitude coordinates on a sphere to xyz Cartesian coordinates.
Arguments
- x
(
matrix
,numeric
,data.frame
) A 2-columnnumeric
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 length3
, the XYZ coordinates of the sphere center.- long
(
character
) Ifx
is adata.frame
, then the column used as longitudes.- lat
(
character
) Ifx
is 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))