3D coordinates on a sphere to Latitude and Longitu

2020-01-27 10:03发布

I've got the following information:

There exists a sphere with origin (0,0,0) and radius R. After doing a ray-sphere intersection I know a point (XYZ) in 3D space that is on the sphere (the exact position in 3D space where the line pierces the sphere hull).

For my program I'd like to calculate the Latitude and Longitude of the XYZ point on the sphere, but I can't think (or Google) up a way to do this easily.

So in short, the function that I'm trying to write is this:

public static LatLon FromVector3(Vector3 position, float sphereRadius)
{
    return Latitude and Longitude
}

Does anybody know how to do this? As a reference this Wiki SVG file might be helpful:

Geographic coordinates

Update:

Thanks for all the helpful answers, so in the end I went with this code:

 public static LatLon FromVector3(Vector3 position, float sphereRadius)
    {
        float lat = (float)Math.Acos(position.Y / sphereRadius); //theta
        float lon = (float)Math.Atan(position.X / position.Z); //phi
        return new LatLon(lat, lon);
    }

Now I've got to think of which answer helped me the most to accept :P.

7条回答
够拽才男人
2楼-- · 2020-01-27 10:43
r=sqrt(x^2+y^2+z^2)  
phi = arccos(sqrt(x^2+y^2)/r)*sign(y)  
lambda = arccos(x/sqrt(x^2+y^2))  
latitude = 180/pi * phi  
longitude = 180/pi * lambda 

you might have to tinker with the signs a little

查看更多
登录 后发表回答