Convert back and forth between latitude/longitude and XYZ-space

xyz2latlon(x, y, z)

latlon2xyz(latitude, longitude)

lonlat2xyz(longitude, latitude)

Arguments

x, y, z

numeric vectors

latitude, longitude

vectors of latitude and longitude values

Value

a matrix each row of which describes the latitudes and longitudes

a matrix each row of which contains the x, y, and z coordinates of a point on a unit sphere

See also

Examples

xyz2latlon(1, 1, 1)     # point may be on sphere of any radius
#>           lat lon
#> [1,] 35.26439  45
xyz2latlon(0, 0, 0)     # this produces a NaN for latitude
#>      lat lon
#> [1,] NaN   0
latlon2xyz(30, 45)
#>             x        y   z
#> [1,] 30.09873 48.75318 0.5
lonlat2xyz(45, 30)
#>             x        y   z
#> [1,] 30.09873 48.75318 0.5