来自经纬度和 three.js 个对象的 n 向量公式

Formula of n-vector from latitude and longitude with three.js objects

我想要根据 three.js 场景中的纬度和经度给出 n 向量(垂直于地球)的公式。 我的代码目前如下,基于城市列表(在 table 中称为 "wup"):

var conegeometry = new THREE.CylinderGeometry(0, 10, 10, 500, false);
var earthRadius = 6371;  // kilometres
var réduc = 0.02;
for (var iter=1;iter<1693;iter++){
    var cone = new THREE.Mesh(conegeometry, conematerial);
    var lat = wup[iter].Latitude*Math.PI/180;
    var lon = wup[iter].Longitude*Math.PI/180;
    cone.position.set (
        earthRadius * réduc * Math.cos(lat) * Math.cos(lon),
        earthRadius * réduc * Math.cos(lat) * Math.sin(lon),
        earthRadius * réduc * Math.sin(lat));
    cone.rotation.set (
        Math.sin(lat),
        Math.cos(lat) * Math.sin(lon),
        -Math.cos(lat) * Math.cos(lon));

    scene.add(cone);
}

公式来自this article, p 402.

我的目标是将所有城市表示为圆锥体,顶部位于 lat/lon 位置,其余部分位于地球表面以下,并垂直于地球表面(简化为球体)。 纬度和经度来自联合国城市数据集,在度数上看起来非常干净和经典。

Santiago Del Estero -27,79511   -64,26149
Yerevan              40,181998  44,514619
Adelaide            -34,92866   138,59863

但是旋转公式有问题,我找不到合适的调整。有什么想法吗?

我找到了一个解决方案,比我最初的想法简单得多。基于 this project 和此示例,使用指令 lookAt 避免了复杂的三角函数公式。

我还发现我的 lat/lon 到 x, y, z 的公式是错误的,并且与我也使用的项目 shp.js 中使用的公式不对应。

可以将对象设置为面向给定点,这里是地球的中心。但是锥体是圆柱体,并且出于某种我不完全理解的原因必须变成 PI/2。所以这有效:

     var lat =   wup[iter].Latitude*Math.PI/180;
     var lon = - wup[iter].Longitude*Math.PI/180;

     cone.position.set (
            Math.cos(lon) * 90 * Math.cos(lat),
            Math.sin(lat) * 90,
            Math.sin(lon) * 90 * Math.cos(lat)
            );
     cone.lookAt( new THREE.Vector3(0,0,0) ); //orientate the cone to the center of earth
     cone.translateZ( - earthRadius * réduc); //to follow the genral contraction
     cone.translateZ( coneHeight/2); //to put the top edge at lat/lon position
     cone.rotateX(- Math.PI / 2 ); //because cylinders.cones are drawn horizontally

您需要解决两件事:位置计算和旋转计算。

职位: 地理坐标系是左手坐标系(经度向东增长)。 Three.js 使用右手坐标系(经度向西增长)。因此,经度值需要在您的几何图形中反转。此外,您找到的公式适用于 Z 轴朝上的坐标。 Three.js Y 轴朝上。所以你需要交换 z 和 y 公式。这是位置的正确代码:

    var lat = wup[iter].Latitude*Math.PI/180;
    var lon = - wup[iter].Longitude*Math.PI/180;

    cone.position.set (
        earthRadius * réduc * Math.cos(lat) * Math.cos(lon),
        earthRadius * réduc * Math.sin(lat),
        earthRadius * réduc * Math.cos(lat) * Math.sin(lon));

旋转: 您只需要将锥体旋转 longitude/latitude 值(不是正弦和余弦)

    cone.rotation.set ( 0, -lon, - Math.PI / 2 + lat);