joh*_*ith 4 javascript geolocation three.js
我正在玩three.js
我想在更大的球体上渲染特定地理坐标上的物体,我非常接近解决方案,但我没有从拉特龙获得正确的xyz位置
我在jsfiddle上设置了一个测试用例,有两个坐标
latlons = [[40.7142700,-74.0059700], [52.5243700,13.4105300]];
Run Code Online (Sandbox Code Playgroud)
它的纽约和柏林
这是我从lat lon和radius计算xyz的函数
function calcPosFromLatLonRad(lat,lon,radius){
// Attempt1
var cosLat = Math.cos(lat * Math.PI / 180.0);
var sinLat = Math.sin(lat * Math.PI / 180.0);
var cosLon = Math.cos(lon * Math.PI / 180.0);
var sinLon = Math.sin(lon * Math.PI / 180.0);
var rad = radius;
y = rad * cosLat * sinLon;
x = rad * cosLat * cosLon;
z = rad * sinLat;
// Attempt2
// x = radius * Math.sin(lat) * Math.cos(lon)
// y = radius * Math.sin(lat) * Math.sin(lon)
// z = radius * Math.cos(lat)
// Attempt3
// latitude = lat * Math.PI/180
// longitude = lon * Math.PI/180
// x = -radius * Math.cos(latitude) * Math.cos(longitude)
// y = radius * Math.sin(latitude)
// z = radius * Math.cos(latitude) * Math.sin(longitude)
// Attempt4
// var phi = (90-lat)*(Math.PI/180);
// var theta = (lng+180)*(Math.PI/180);
// x = ((rad) * Math.sin(phi)*Math.cos(theta));
// z = ((rad) * Math.sin(phi)*Math.sin(theta));
// y = ((rad) * Math.cos(phi));
console.log([x,y,z]);
return [x,y,z];
}
Run Code Online (Sandbox Code Playgroud)
但是所有尝试都返回不同的xy,并且它们都不正确(z总是正确的).
有人可以请求以正确的方式引导我吗?我不知道会出现什么问题
继承人玩弄小提琴
joh*_*ith 13
不幸的是我无法进一步解释,但在玩完这个之后就像魅力一样:)
function calcPosFromLatLonRad(lat,lon,radius){
var phi = (90-lat)*(Math.PI/180)
var theta = (lon+180)*(Math.PI/180)
x = -((radius) * Math.sin(phi)*Math.cos(theta))
z = ((radius) * Math.sin(phi)*Math.sin(theta))
y = ((radius) * Math.cos(phi))
return [x,y,z]
}
Run Code Online (Sandbox Code Playgroud)
是的,非常酷,不是吗?我仍然对一些较短的等式感兴趣
这个功能对我有用:
function calcPosFromLatLonRad(radius, lat, lon) {
var spherical = new THREE.Spherical(
radius,
THREE.Math.degToRad(90 - lon),
THREE.Math.degToRad(lat)
);
var vector = new THREE.Vector3();
vector.setFromSpherical(spherical);
console.log(vector.x, vector.y, vector.z);
return vector;
}
calcPosFromLatLonRad(0.5, -74.00597, 40.71427);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4706 次 |
最近记录: |