我有以下信息:
存在一个以原点 (0,0,0) 为中心、半径为 R 的球体。在进行光线和球体的交点计算后,我得到了一个存在于球体上的三维空间中的点 (XYZ)。(该点是直线穿过球体表面的精确位置。)
我想要为我的程序计算 XYZ 点所在球体的纬度和经度,但是我无法轻易地想出(或者在谷歌上搜到)实现这一目标的方法。
简言之,我要编写的函数如下:
public static LatLon FromVector3(Vector3 position, float sphereRadius)
{
return Latitude and Longitude
}
请问有人知道如何做到这一点吗?参考这个维基SVG文件可能会有帮助:
更新:
感谢所有提供帮助的答案,最终我选择了这个代码:
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);
}
现在我得想想哪个答案对我帮助最大要选择接受 :P。
float latitude = -((float)acosf(result.localCoordinates.y / sphereRadius) - M_PI_2); //theta float longitude = M_PI - ((float)atan2f(result.localCoordinates.z, result.localCoordinates.x));/ //phi if (longitude > M_PI) { longitude = longitude - (2.0 * M_PI); }
- PKCLsoft