[英]How to plot points on a 3D sphere with ThreeJS
我最近才開始研究 ThreeJS。 目前我正在嘗試 plot 球體上的一個點,但它似乎是在南半球而不是北半球繪制的。 在垂直方向上,它看起來位於球體底部而不是頂部的正確位置。 我從這個答案中獲取了一些代碼: https://stackoverflow.com/a/8982005/738201
在圖像中,帶有紅色框的黃線是我的標繪點。 它應該在紐約州北部地區,而不是現在的位置。
最后,代碼。
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}
我懷疑問題可能是在 3D 球體上使用 2D 坐標,但如果是這樣,我不太確定如何糾正它。
試試這個,這將有助於在 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.