球体上的 3D 坐标为纬度和经度

发布于 2024-11-01 17:06:25 字数 803 浏览 2 评论 0原文

我得到以下信息:

存在一个原点为 (0,0,0)、半径为 R 的球体。 进行射线球体相交后,我知道 3D 空间中球体上的一个点 (XYZ)(直线穿过球体外壳的 3D 空间中的确切位置)。

对于我的程序,我想计算球体上 XYZ 点的纬度和经度,但我无法想出(或谷歌)轻松完成此操作的方法。

简而言之,我想要编写的函数是这样的:

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

有人知道如何做到这一点吗?作为参考,此 Wiki 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。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

滥情稳全场 2024-11-08 17:06:25

我想从 x,y,z(3d 坐标系)找到球极坐标应该不难。

  1. r 如果位于表面,则始终保持不变。

    在此处输入图像描述

  2. (90 - θ)您的纬度(负值表示位于底部),从顶部测量

    在此处输入图像描述

  3. φ 是您的经度。 (但不太确定经度系统)

    在此处输入图像描述

另请从 维基百科

在此处输入图像描述

I guess it should not be difficult to find the spherical polar coordinates from x,y,z (3d-coordinate system).

  1. r is always constant if it's on surface.

    enter image description here

  2. (90 - θ) your latitude (negative means it's on the bottom) as it's measured from top.

    enter image description here

  3. φ is your longitude. (but not quite sure about longitude system)

    enter image description here

Also check this diagram from wikipedia.

enter image description here

木有鱼丸 2024-11-08 17:06:25
lat=atan2(z,sqrt(x*x+y*y))
lng=atan2(y,x)

将公式与 atan2() 一起使用会更方便。
您不必加/减 pi/2 或关心不同象限中的符号问题或除以零。

lat 在北半球将 >0
lat 在南半球将<0
lng 在东半球将 >0
lng 在西半球将 <0

lat=atan2(z,sqrt(x*x+y*y))
lng=atan2(y,x)

Using formulas with atan2() is more convenient.
You don't have to add/subtract pi/2 or care about sign issues in different quadrants or division by zero.

lat will be >0 in the northern hemisphere
lat will be <0 in the southern hemisphere
lng will be >0 in the eastern hemisphere
lng will be <0 in the western hemisphere

你在看孤独的风景 2024-11-08 17:06:25

这有助于使用 Javascript/THREE.js:

var lat = 90 - (Math.acos(y / RADIUS_SPHERE)) * 180 / Math.PI;
var lon = ((270 + (Math.atan2(x , z)) * 180 / Math.PI) % 360) -180;

This helped using Javascript/THREE.js:

var lat = 90 - (Math.acos(y / RADIUS_SPHERE)) * 180 / Math.PI;
var lon = ((270 + (Math.atan2(x , z)) * 180 / Math.PI) % 360) -180;
予囚 2024-11-08 17:06:25
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 

你可能需要稍微修改一下标志

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

半岛未凉 2024-11-08 17:06:25

编辑 - 重读您的问题后,我的答案不一定适用,但我会将其保留以供参考。

这取决于您想要的准确度以及结果的用途。不存在单一的纬度和经度系统,例如 WGS84(美国 GPS)或 ETRS89(欧洲 GPS)略有不同,并且随着大西洋变宽而发散。

http://www.ordnancesurvey.co.uk/oswebsite /gps/information/coordinatesystemsinfo/guidecontents/guide5.html

http://www.ordnancesurvey.co.uk/oswebsite/gps /information/coordinatesystemsinfo/guidecontents/guide6.html

最后,这应该可以直接解决您的问题。

http://www.ordnancesurvey.co.uk/oswebsite /gps/information/coordinatesystemsinfo/guidecontents/guideb.html

http://www.ordnancesurvey.co.uk/oswebsite/gps/docs/convertingcooperatives3D .pdf

Edit - having reread you question my answer isn't necessarily applicable, but I'll leave it up for reference.

It depends how accurate you wan to be an dwhat purpose you are going to use the result for. There is no single latitude and logitude system, eg WGS84 (USA GPS) or ETRS89 (European GPS) differ slightly and are diverging as the Atlantic Ocean widens.

http://www.ordnancesurvey.co.uk/oswebsite/gps/information/coordinatesystemsinfo/guidecontents/guide5.html

http://www.ordnancesurvey.co.uk/oswebsite/gps/information/coordinatesystemsinfo/guidecontents/guide6.html

Finally this should address your question directly.

http://www.ordnancesurvey.co.uk/oswebsite/gps/information/coordinatesystemsinfo/guidecontents/guideb.html

or

http://www.ordnancesurvey.co.uk/oswebsite/gps/docs/convertingcoordinates3D.pdf

假面具 2024-11-08 17:06:25

在研究了使用纬度/经度将对象放置在球体上的简单解决方案之后,我想出了一个简单的类,让您可以使用 Three.js 来完成此操作。

var earth = new THREE.GeoSpatialMap(geometry, material);
earth.setTexturesEdgeLongitude(-180.806168);

for (i = 0; i < continentData.length; i += step) {

    var lat = continentData[i];
    var lng = continentData[i + 1];

    var light = new THREE.PointLight(0x0099ff);
    var plant = new org.good.ecology.Plant();
    plant.scale.x = plant.scale.y = plant.scale.z = Math.random() * 3;

    console.log("Adding symbol at: " + lat + " : " + lng);
    earth.addGeoSymbol(
        new THREE.GeoSpatialMap.GeoSymbol(plant, {
            phi: lat,
            lambda: lng
        })
    );


    plant.lookAt(earth.position);

}

https://github.com/scottbyrns/Three.js-Geospatial-Mapping

After working on getting a straightforward solution to placing objects on a sphere using lat/lng, I came up with a simple class to let you do it using three.js.

var earth = new THREE.GeoSpatialMap(geometry, material);
earth.setTexturesEdgeLongitude(-180.806168);

for (i = 0; i < continentData.length; i += step) {

    var lat = continentData[i];
    var lng = continentData[i + 1];

    var light = new THREE.PointLight(0x0099ff);
    var plant = new org.good.ecology.Plant();
    plant.scale.x = plant.scale.y = plant.scale.z = Math.random() * 3;

    console.log("Adding symbol at: " + lat + " : " + lng);
    earth.addGeoSymbol(
        new THREE.GeoSpatialMap.GeoSymbol(plant, {
            phi: lat,
            lambda: lng
        })
    );


    plant.lookAt(earth.position);

}

https://github.com/scottbyrns/Three.js-Geospatial-Mapping

も星光 2024-11-08 17:06:25

这是粗略的工作,但是:

Lat = arctan(z/(sqrt(x^2+y^2)))

Long = arccos(sqrt(x^2+y^2)/x)

This is back-of-envelope work but:

Lat = arctan(z/(sqrt(x^2+y^2)))

Long = arccos(sqrt(x^2+y^2)/x)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文