java - Java中的多点三边测量算法

标签 java android gps indoor-positioning-system trilateration

我正在尝试在我的 Android 应用程序中实现三边测量算法以确定用户的室内位置。我正在使用超宽带信标来获取到固定点的距离。我能够采用 Trilateration Method Android Java 中建议的方法如下:

public LatLng getLocationByTrilateration(
        LatLng location1, double distance1,
        LatLng location2, double distance2,
        LatLng location3, double distance3){

    //DECLARE VARIABLES

    double[] P1   = new double[2];
    double[] P2   = new double[2];
    double[] P3   = new double[2];
    double[] ex   = new double[2];
    double[] ey   = new double[2];
    double[] p3p1 = new double[2];
    double jval  = 0;
    double temp  = 0;
    double ival  = 0;
    double p3p1i = 0;
    double triptx;
    double tripty;
    double xval;
    double yval;
    double t1;
    double t2;
    double t3;
    double t;
    double exx;
    double d;
    double eyy;

    //TRANSALTE POINTS TO VECTORS
    //POINT 1
    P1[0] = location1.latitude;
    P1[1] = location1.longitude;
    //POINT 2
    P2[0] = location2.latitude;
    P2[1] = location2.longitude;
    //POINT 3
    P3[0] = location3.latitude;
    P3[1] = location3.longitude;

    //TRANSFORM THE METERS VALUE FOR THE MAP UNIT
    //DISTANCE BETWEEN POINT 1 AND MY LOCATION
    distance1 = (distance1 / 100000);
    //DISTANCE BETWEEN POINT 2 AND MY LOCATION
    distance2 = (distance2 / 100000);
    //DISTANCE BETWEEN POINT 3 AND MY LOCATION
    distance3 = (distance3 / 100000);

    for (int i = 0; i < P1.length; i++) {
        t1   = P2[i];
        t2   = P1[i];
        t    = t1 - t2;
        temp += (t*t);
    }
    d = Math.sqrt(temp);
    for (int i = 0; i < P1.length; i++) {
        t1    = P2[i];
        t2    = P1[i];
        exx   = (t1 - t2)/(Math.sqrt(temp));
        ex[i] = exx;
    }
    for (int i = 0; i < P3.length; i++) {
        t1      = P3[i];
        t2      = P1[i];
        t3      = t1 - t2;
        p3p1[i] = t3;
    }
    for (int i = 0; i < ex.length; i++) {
        t1 = ex[i];
        t2 = p3p1[i];
        ival += (t1*t2);
    }
    for (int  i = 0; i < P3.length; i++) {
        t1 = P3[i];
        t2 = P1[i];
        t3 = ex[i] * ival;
        t  = t1 - t2 -t3;
        p3p1i += (t*t);
    }
    for (int i = 0; i < P3.length; i++) {
        t1 = P3[i];
        t2 = P1[i];
        t3 = ex[i] * ival;
        eyy = (t1 - t2 - t3)/Math.sqrt(p3p1i);
        ey[i] = eyy;
    }
    for (int i = 0; i < ey.length; i++) {
        t1 = ey[i];
        t2 = p3p1[i];
        jval += (t1*t2);
    }
    xval = (Math.pow(distance1, 2) - Math.pow(distance2, 2) + Math.pow(d, 2))/(2*d);
    yval = ((Math.pow(distance1, 2) - Math.pow(distance3, 2) + Math.pow(ival, 2) + Math.pow(jval, 2))/(2*jval)) - ((ival/jval)*xval);

    t1 = location1.latitude;
    t2 = ex[0] * xval;
    t3 = ey[0] * yval;
    triptx = t1 + t2 + t3;

    t1 = location1.longitude;
    t2 = ex[1] * xval;
    t3 = ey[1] * yval;
    tripty = t1 + t2 + t3;


    return new LatLng(triptx,tripty);

}

使用这种方法可以获得用户位置,但不是很准确。我如何扩展它以使用超过 3 个已知位置/距离?理想情况下 N>=3 的点数。

最佳答案

如果以正确的方式表述,多点定位问题就是一个优化问题。

大多数学术示例,例如 wikipedia 上的示例, 正好处理三个圆圈并假设信息完全准确。这些情况允许更简单的问题公式和准确的答案,并且通常不能满足您所描述的实际情况。

R2 或 R3 欧几里德空间中距离包含测量误差的问题,通常取而代之的是感兴趣的面积(椭圆)或体积(椭球)的一点。如果需要点估计而不是区域,则应使用面积质心或体积质心。 R2空间需要至少3个非退化点和距离才能得到唯一区域;同理,R3空间至少需要4个非退化点和距离,才能得到唯一区域。

这是一个可以轻松满足您需求的开源 Java 库: https://github.com/lemmingapex/Trilateration

trilateration

它使用 Apache Commons Math 中流行的非线性最小二乘优化器 Levenberg-Marquardt 算法。

double[][] positions = new double[][] { { 5.0, -6.0 }, { 13.0, -15.0 }, { 21.0, -3.0 }, { 12.42, -21.2 } };
double[] distances = new double[] { 8.06, 13.97, 23.32, 15.31 };

NonLinearLeastSquaresSolver solver = new NonLinearLeastSquaresSolver(new TrilaterationFunction(positions, distances), new LevenbergMarquardtOptimizer());
Optimum optimum = solver.solve();

// the answer
double[] calculatedPosition = optimum.getPoint().toArray();

// error and geometry information
RealVector standardDeviation = optimum.getSigma(0);
RealMatrix covarianceMatrix = optimum.getCovariances(0);

关于java - Java中的多点三边测量算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30336278/

相关文章:

android - 为什么跳过 gradle war 任务?

android - 此应用将受到 Google Play 管理短信和通话记录权限使用政策变更的影响

android - 仅在位置更改时更新位置

java - 从单例切换到应用程序对象,仍然出现空指针异常

java - 初学者循环 GUI

android - Android 版 OpenCV : failed to load cascade classifier error

ios - Cordova geolocation.getCurrentPosition 在 iPad 上抛出超时

android - 位置经理内部服务

java - 如何在 JfreeChart SaveAsPNG 方法中实现 SaveAs 对话框

java - 请帮我弄清楚这个网络代理代码有什么问题