I have some global data (seismic data from earthquakes) that was provided as geocentric (cartesian) coordinates. Basically, the coordinates range from +1 to -1 for x, y and z axes. The center of the earth is at coordinates 0, 0, 0. I need to convert these to latitude, longitude and elevation (altitude). . I believe I have been able to convert the coordinates to latitude and longitude using the equations provided in this link and applying them in Field Calculator.

Basically, the logic is as follows:

latitude(r, x, y, z) = arcsin(z/r)(180/π)

longitude(r, x, y, z) =

if (x > 0) {

arctan(y/x)(180/π)

} else if (y > 0) {

arctan(y/x)(180/π) + 180

} else {

arctan(y/x)(180/π) - 180

}

But I'm not sure how to calculate the elevation or depth. I tried using the equation below to calculate the depth (from the earth's surface in meters (using the radius of the earth = 6378km)

6378100 - ((sqrt(x^2 + y^2 + z^2)*6378100)

However, for the shallow points (with elevations near 0), the points cover the entire earth but for points at 2800km depth, the number of points are much less and do not cover the entire earth when mapped in a geographic or projected coordinate system. Therefore, I'm suspecting that my elevation (depth) calculations are not correct. Any advice would be greatly appreciated.

There are equations here: https://gssc.esa.int/navipedia/index.php/Ellipsoidal_and_Cartesian_Coordinates_Conversion