2010-07-04 87 views
0

如何将经纬度热点投影到360x180度全景图像上?
使用javascript?javascript:lat/lon,lat1/lon1,方位,距离x,y屏幕坐标?

真实数据:
十进制度和米高空 经/纬度:
摄像机坐标:49.994249,8.66539,2
热点坐标:49.994163,8.665388,2

距离相机米热点:9.55
指南针轴承摄像机以度(0-360)为热点:170
图像方向:130度(图像中间x)这是否需要?
Horizo​​n是图像的中间部分。

图像大小宽度:1024,高度:512像素

我需要的是JavaScript代码,以确定热点的X,Y像素图像坐标。
0是左上角。

准确性不重要。距离总是小于100米。

感谢,

janmartin AT DIY-街景DOT ORG

回答

0

看起来你已经完成了艰难的部分:转换GPS坐标到相对轴承(和距离)。

如果360°图像的中心指向北方130度(假设指南针为顺时针方向),并且来自摄像机位置和热点的方位距北方170度,则看起来热点位于相对于图像中心的图像40°。而且,由于图像水平包含360°和1024像素,因此热点位于距图像中心1024像素/ 360度* 40度= 114像素处。

而且由于相机和热点都在相同的高度,所以相对音高为零。

把这个在一起,你得到的坐标:512 + 114,256 + 0 =坐标:626,256

如果热点的高度是不一样的相机,那么你就必须使用一些简单的三点法来计算音调:

首先让我们假设ground distance =相机位置和热点位置之间的地平线距离。无论每个海拔高度如何,这都是一样的。

所以,你的音高应该是:atan [(热点高度 - 相机高度)/地面距离]。

举例来说,如果你有100米地距离和热点都在10.75米用相机仍然2m处的高度,那么你会计算你的间距:

间距= ATAN [(10.75米 - 2m)/ 100m] = atan(8.75m/100m)= atan(0.0875)= 5°

要在全景图上显示:512px/180°* 5°= 14px高于中间。由于中间是256像素,图像的左上角是0,0,因此我们将从256减去14像素以达到242像素。

把所有这一切汇集成JavaScript作为你的要求:

// We'll use degrees, but this would be simpler if 
// everything were computed in radians, since that 
// is how the Math methods work. 
function getRelativePitch(cameraAlt, hsAlt, groundDistance) 
{ 
    var degPerRad = 180/Math.PI; 

    if (groundDistance == 0) { return 0.0; } // fringe case 

    var rad = Math.atan((hsAlt - cameraAlt)/groundDistance); 

    // Convert to degress 
    return rad * degPerRad; 
} 

// Pretty simply this one. 
function getRelativeHeading(cameraHeading, hsHeading) 
{ 
    return hsHeading - cameraHeading; 
} 

var cameraHeading = 130; // degrees 
var hotspotHeading = 170; // degrees 
var cameraAltitude = 2; // meters 
var hotspotAltitude = 10.75; // meters 
var groundDistance = 100; // meters 

var panoWidth = 1024; // pixels 
var panoHeight = 512; // pixels 

var panoRangeX = 360; // degrees 
var panoRangeY = 180; // degrees 

var relativeHeading = getRelativeHeading(cameraHeading, hotspotHeading); 
var relativePitch = getRelativePitch(cameraAltitude, hotspotAltitude, groundDistance); 

// Now convert to pixels 
var hotspotX = Math.round(panoWidth/2 + panoWidth/panoRangeX * relativeHeading); 
var hotspotY = Math.round(panoHeight/2 - panoHeight/panoRangeY * relativePitch); 

// Just in case we endup out of range 
while (hotspotX < 0) { hotspotX += panoWidth; } 
while (hotspotX > panoWidth) { hotspotX -= panoWidth; } 

while (hotspotY < 0) { hotspotY += panoHeight; } 
while (hotspotY > panoHeight) { hotspotY -= panoHeight; } 

alert("Hotspot is at: " + hotspotX + ", " + hotspotY); 

我希望这有助于!