Java中的多点三边测量算法

2024-03-25

我正在尝试在我的 Android 应用程序中实现三边测量算法来确定用户的室内位置。我正在使用超宽带信标来获取到固定点的距离。我能够采用中建议的方法三边测量法 Android Java https://stackoverflow.com/questions/24761658/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 个点,其中 N>=3。


当以正确的方式表述时,多边定位问题是一个优化问题。

大多数学术例子,例如维基百科 https://en.wikipedia.org/wiki/Trilateration,处理恰好三个圆圈并假设完全准确的信息。这些情况允许更简单的问题表述和准确的答案,并且通常不能满足您所描述的实际情况。

The problem in R2 or R3 euclidean space with distances that contain measurement error, an area (ellipse) or volume (ellipsoid) of interest is usually obtained instead of a point. If a point estimate is desired instead of a region, the area centroid or volume centroid should be used. R2 space requires at least 3 non-degenerate points and distances to obtain a unique region; and similarly R3 space requires at least 4 non-degenerate points and distances to obtain a unique region.

这是一个开源的java库,可以轻松满足您的需求:https://github.com/lemmingapex/Trilateration https://github.com/lemmingapex/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);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Java中的多点三边测量算法 的相关文章

随机推荐

  • 在 Selenium Python 绑定中设置页面加载超时

    我正在使用带有 Selenium 模块的 Python 编写一个机器人 当我用我的机器人打开一个网页时 由于该网页包含的外部源比 dom 多 所以需要花费很多时间才能加载所有页面 我使用显式和隐式等待来消除这个问题 因为我只想加载特定元素而
  • Spring获取ServletContext并将其作为Bean提供

    I want to get the ServletContext in a Java Spring Webproject and use it to get the absolute path of my web application p
  • 如何从 AWS AppStream 中获取当前用户?

    我正在通过 AWS AppStream 对应用程序的部署进行原型设计 对流的访问通过 Web 门户 使用 SAML 进行管理 我的应用程序需要知道用户的身份 我可以提示他们 但我不想让他们同时登录门户和应用程序 我想获取他们在门户网站上提供
  • 如何获取雪花中表的上次访问时间戳?

    我想获取雪花中表的上次访问时间戳 并不总是理想的 但对于一次性问题找到此问题的一种快速方法是使用 QUERY HISTORY SELECT START TIME FROM TABLE INFORMATION SCHEMA QUERY HIS
  • Presto 中包含 ' ' 字符的键的 JSON_EXTRACT 问题

    我正在使用 Presto 0 163 来查询数据 并尝试从 json 中提取字段 我有一个如下所示的 json 它出现在 style attributes 列中 attributes Brand Fit Name Regular Fit F
  • AndroidManifest.xml 中的属性 application@allowBackup value=(false) 也存在于 [:barcodescanner:] AndroidManifest.xml value=(true)

    我尝试将 ionic 3 应用程序清单中的 allowedBackup 属性设置为 false 但 gradle 抱怨以下错误 AndroidManifest xml 4 18 45 中的属性 application allowBackup
  • iOS 7 图标文件名

    如何命名 Xcode 5 的图标文件 它总是给出错误 说明应用程序不在顶层 这真的很令人沮丧 有人可以给我每个分辨率都必须使用的文件名吗 ios 7 兼容应用程序的图标文件名和大小如下 iPhone 图标 png 57 57 电子邮件受保护
  • Amazon AWS Cognito 和 Python Boto3 建立 AWS 连接并将文件上传到 Bucket

    我正在尝试使用 AWS cognito 服务来验证和上传文件 我已获得了 RegionType identityPool AWS 账户 ID 和 UnAuthRole 我还知道生产和开发桶的名称 我想我正在设置 AWS 访问密钥和 AWS
  • PHP 延迟 10 分钟后执行代码

    我需要在事件 表单提交 后延迟 10 分钟执行 PHP 中的某些代码 例如 发送电子邮件 实现这一目标的最佳方法是什么 我唯一的选择是每分钟运行一次 Cronjob 吗 这对于共享主机实用吗 使用 cronjobs 是最好的方法 如果您无法
  • android 地图异步加载覆盖项

    我有一个地图视图 其中包含我想要加载的数千个项目 显然 在创建视图时我无法加载它们 我想我必须根据当前显示的内容异步加载它们 如何仅加载屏幕上显示的地图部分中的项目 使用 AsyncTask 加载每个屏幕的各个层 使用 MapView ap
  • latin-1 转 ascii

    我有一个带有重音拉丁字符的 unicode 字符串 例如 n unicode Wikip dia le projet d encyclop die utf 8 我想将其转换为普通的 ascii 即 Wikipedia le projet d
  • R 将列表列表转换为数据帧

    我需要处理受密码保护的 Excel xlsx 工作簿中提供的数据 出于法律原因 我无法创建不受保护的 Excel 文件或 csv 文件等并从那里进行处理 所有 Excel 导入包都无法处理受密码保护的工作簿 从这个答案将受密码保护的 xls
  • 双型比较器

    我编写了以下代码 public class NewClass2 implements Comparator
  • 如何在android项目中安装openssl.so和libssl.so?

    我目前面临 openssl 的构建问题 我首先建造了libssl so and libcrypto so与 ndk build 守护者项目共享库 第二步 我通过执行以下操作将库与我的 Android 项目集成 如本中所述topic http
  • 在 javascript 中模拟打字的外观,而不是实际的按键

    我正在尝试编写一个简单的函数 让它看起来好像有人正在输入textarea 这是我的函数 如果它很糟糕 请原谅我 但我通常不使用 javascript 这console log 部分工作正常 但由于某种原因我无法让这个脚本按照我期望的方式更新
  • 转义并在邮件客户端中显示(mailto 链接)

    我有一个像这样的 JavaScript 函数 var strBody encodeURI window location href var strSubject encodeURI document title var mailto lin
  • 使用 str.format() 访问对象属性

    我有一个带有属性的 Python 对象a b c 我仍然使用旧的字符串格式 所以我通常会手动打印这些 print My object has strings a s b s c s obj a obj b obj c 最近 我的字符串变得超
  • PySpark 中的 PCA 分析

    看着http spark apache org docs latest mllib Dimensionality reduction html http spark apache org docs latest mllib dimensio
  • 致命:用户“root”postgresql 的密码身份验证失败

    我使用 PostgreSQL 和 Django Heroku 格式 并出现错误 致命 用户 root 的密码身份验证失败 Traceback most recent call last File manage py line 10 in
  • Java中的多点三边测量算法

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