简体   繁体   English

如何使用 ThreeJS 在 3D 球体上 plot 点

[英]How to plot points on a 3D sphere with ThreeJS

I just recently started delving into ThreeJS.我最近才开始研究 ThreeJS。 Currently I'm trying to plot a point on a sphere but it appears to be plotting in the southern hemispehre instead of the northern hemisphere.目前我正在尝试 plot 球体上的一个点,但它似乎是在南半球而不是北半球绘制的。 Vertically, it looks to be in the correct spot just on the bottom of the sphere instead of the top.在垂直方向上,它看起来位于球体底部而不是顶部的正确位置。 I grabbed some code from this answer: https://stackoverflow.com/a/8982005/738201我从这个答案中获取了一些代码: https://stackoverflow.com/a/8982005/738201

In the image the yellow line with the red box is my plotted point.在图像中,带有红色框的黄线是我的标绘点。 It should be in the upstate NY region instead of where it is now.它应该在纽约州北部地区,而不是现在的位置。在此处输入图像描述

And lastly, the code.最后,代码。

function xyz(lat, lon){
    var cosLat = Math.cos(lat*Math.PI/180.00);
    var sinLat = Math.sin(lat*Math.PI/180.00);
    var cosLon = Math.cos(lon*Math.PI/180.00);
    var sinLon = Math.sin(lon*Math.PI/180.00);
    var r = sphere.geometry.radius; //50

    var coords = {};
    coords.x = r * cosLat * cosLon;
    coords.y = r * cosLat * sinLon;
    coords.z = r * sinLat;

    console.log(coords);

    return coords;
}

// Lat/Lon from GoogleMaps
var coords = xyz(42.654162, -73.699830);
// returns {x: 10.321018160637124, y: -35.29474079777381, z: 33.878575178802286} 

I suspect that the issue may be using 2D coords on a 3D sphere but if so, I'm not quite sure how to rectify that.我怀疑问题可能是在 3D 球体上使用 2D 坐标,但如果是这样,我不太确定如何纠正它。

Try this, It will help to use directly lat and long on the map试试这个,这将有助于在 map 上直接使用经纬度

function calcPosFromLatLon(phi, theta){
let lat = (90 - phi) * (Math.PI/180);

let lon = (theta + 180) * (Math.PI/180);

const x = -(Math.sin(lat)* Math.cos(lon))
const z = Math.sin(lat) * Math.sin(lon)
const y = Math.cos(lat)
}
calcPosFromLatLon(//coordinates here//)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM