【发布时间】:2019-08-22 00:44:53
【问题描述】:
我正在构建一个简单的应用程序,它会在您的屏幕上放置一个标记,该标记位于现实世界中某些地标的顶部,将标记覆盖在相机的视图上。 我有查看设备和世界地标的纬度/经度/高度,并将它们转换为 ECEF 坐标。但是我在 3D 投影数学上遇到了麻烦。这个点似乎总是放在屏幕的中间……也许我的缩放比例在某个地方是错误的,所以看起来它几乎没有从中心移动?
查看设备 GPS 坐标:
GPS:
lat: 45.492132
lon: -122.721062
alt: 124 (meters)
ECEF:
x: -2421034.078421273
y: -3768100.560012433
z: 4525944.676268726
地标 GPS 坐标:
GPS:
lat: 45.499278
lon: -122.708417
alt: 479 (meters)
ECEF:
x: -2420030.781624382
y: -3768367.5284123267
z: 4526754.604333807
我尝试按照 here 的数学运算来构建一个函数,从 3D 点坐标中获取屏幕坐标。
当我将这些 ECEF 点放入我的投影函数时,视口为 1440x335,我得到:x: 721, y: 167
这是我的功能:
function projectionCoordinates(origin, destination) {
const relativeX = destination.x - origin.x;
const relativeY = destination.y - origin.y;
const relativeZ = destination.z - origin.z;
const xPerspective = relativeX / relativeZ;
const yPerspective = relativeY / relativeZ;
const xNormalized = (xPerspective + viewPort.width / 2) / viewPort.width;
const yNormalized = (yPerspective + viewPort.height / 2) / viewPort.height;
const xRaster = Math.floor(xNormalized * viewPort.width);
const yRaster = Math.floor((1 - yNormalized) * viewPort.height);
return { x: xRaster, y: yRaster };
}
我认为这个点应该放在屏幕上更高的位置。我链接的那篇文章提到了我无法遵循的 3x4 矩阵(不确定如何从 3D 点构建 3x4 矩阵)。也许这些很重要,尤其是因为我最终将不得不考虑设备的倾斜度(用手机向上或向下看)。
如果需要,这是我将纬度/经度/高度坐标转换为 ECEF 的函数(从另一个 SO 答案复制/粘贴):
function llaToCartesion({ lat, lon, alt }) {
const cosLat = Math.cos((lat * Math.PI) / 180.0);
const sinLat = Math.sin((lat * Math.PI) / 180.0);
const cosLon = Math.cos((lon * Math.PI) / 180.0);
const sinLon = Math.sin((lon * Math.PI) / 180.0);
const rad = 6378137.0;
const f = 1.0 / 298.257224;
const C =
1.0 / Math.sqrt(cosLat * cosLat + (1 - f) * (1 - f) * sinLat * sinLat);
const S = (1.0 - f) * (1.0 - f) * C;
const h = alt;
const x = (rad * C + h) * cosLat * cosLon;
const y = (rad * C + h) * cosLat * sinLon;
const z = (rad * S + h) * sinLat;
return { x, y, z };
}
【问题讨论】:
标签: javascript 3d computer-vision projection