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:
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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…