每次都生成相同坐标的本地化多纬度代码?

问题描述

编辑:本地化始终围绕x=1980.000032943933547358028590679168701171875,y=3191.99997642902735606185160577297210693359375

我编写了以下代码来解决“到达时间延迟”问题。也就是说,考虑到三个观察者的位置,某些信号的速度以及每个接收器“看到”信号的时间,我想定位信号源。在这里,我们假设源和观察者在二维平面(平面欧几里德空间)中。

我的解决方法如下:

鉴于每个观察者看到信号的时间,我选择一个接收器作为“基线”,我将其设为t = 0。然后,我从其他两名观察员的到达时间中减去该时间。现在,我为每个观察者分配一个圆,其半径由该差异给出(“基线”观察者以r = 0开头),然后我逐渐增加每个圆的半径,直到三个圆都在某个点相交。

实际上,它们不可能在单个点上精确地相交,因为对于一个点,每次迭代我只能将半径增加离散量,我们还假设,但不知道观察者的时钟是精确同步的。

为解决此问题,我改编了Paul Bourke的代码:http://paulbourke.net/geometry/circlesphere/tvoght.c(此处的原因是:http://paulbourke.net/geometry/circlesphere/)。我的改编与这一改编大致相同:https://stackoverflow.com/a/19724186/14073182


我的问题是,代码总是会产生相同的本地化,精确到一个单位的十分之一。我尝试生成一些伪数据(即,选择某个位置,计算预期的延迟,将其馈送到算法中,并查看它是否重构了正确的本地化),并且该算法仍会产生大致相同的本地化……即,非常接近中心三个接收器所形成的三角形中的一个。

知道我在做什么错吗?我已经和一些人(从事GIS,大地测量学,相似领域和数学家的物理学家)进行了交谈,但是却一无所获。

下面是我的代码(考虑到所有事情,它很简短)。要本地化某些源,请调用localizeSource(a,b,c,&xf,&xy)。其中abc是延迟(半径),而xfxy是本地化坐标的存储位置。 / p>

#define EPSILON 0.0001     // Define some threshold

#define x0  3000.00
#define y0  3600.00
#define x1  2100.00
#define y1  2100.00
#define x2  0960.00
#define y2  3600.00

bool findIntersection(double r0,double r1,double r2,double *xf,double *yf){

    double a,dx,dy,d,h,rx,ry;
    double point2_x,point2_y;

    dx = x1 - x0;
    dy = y1 - y0;

    d = sqrt((dy*dy) + (dx*dx));

    if (d > (r0 + r1))
    {
        return false;
    }

    a = ((r0*r0) - (r1*r1) + (d*d)) / (2.0 * d) ;

    point2_x = x0 + (dx * a/d);
    point2_y = y0 + (dy * a/d);

    h = sqrt((r0*r0) - (a*a));

    rx = -dy * (h/d);
    ry = dx * (h/d);

    double intersectionPoint1_x = point2_x + rx;
    double intersectionPoint2_x = point2_x - rx;
    double intersectionPoint1_y = point2_y + ry;
    double intersectionPoint2_y = point2_y - ry;

    dx = intersectionPoint1_x - x2;
    dy = intersectionPoint1_y - y2;
    double d1 = sqrt((dy*dy) + (dx*dx));

    dx = intersectionPoint2_x - x2;
    dy = intersectionPoint2_y - y2;
    double d2 = sqrt((dy*dy) + (dx*dx));

    if(fabs(d1 - r2) < EPSILON) {

        std::cout << std::setprecision(100) << intersectionPoint1_x << "," << intersectionPoint1_y << "\n";
        *xf = intersectionPoint1_x; *yf = intersectionPoint1_y;
        return true;
        
    }
    else if(fabs(d2 - r2) < EPSILON) {

        std::cout << std::setprecision(100) << intersectionPoint2_x << "," << intersectionPoint2_y << "\n";
        *xf = intersectionPoint2_x; *yf = intersectionPoint2_y;
        return true;
        
    }
    else {
        return false;
    }

}

void localizeSource(double r0,double *yf){

    bool foundSource = false;

    while(foundSource == false){
        foundSource = findIntersection(r0,r1,r2,xf,yf);
        r0 += 0.0001; r1 += 0.0001; r2 += 0.0001;
    }


}

int main(){
    
    double xf,xy;
    localizeSource(1000,3000,&xy);
    
}

解决方法

目前还不清楚您要解决的是什么...您的问题是关于“到达时间的延迟”的,但随后您链接到“圆的交点”算法。 TDoA算法使用抛物线而不是圆。

到达时间差算法:

SO上的某人已经使用Fang的方法编写了示例代码 Issues implementing the Fang Algorithm for TDOA Trilateration

Hyperbolic Position Location Estimation in the Multipath Propagation Environment Time Difference of Arrival (TDoA) Localization Combining Weighted Least Squares and Firefly Algorithm

如果您只是在寻找“三角剖分/三角剖分”公式:

A = 2*x2 - 2*x1
B = 2*y2 - 2*y1
C = r1*r1 - r2*r2 - x1*x1 + x2*x2 - y1*y1 + y2*y2
D = 2*x3 - 2*x2
E = 2*y3 - 2*y2
F = r2*r2 - r3*r3 - x2*x2 + x3*x3 - y2*y2 + y3*y3
x = (C*E - F*B) / (E*A - B*D)
y = (C*D - A*F) / (B*D - A*E)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...