tuupola/trilateration

0.2.1 2018-11-12 09:07 UTC

This package is auto-updated.

Last update: 2024-08-29 04:53:50 UTC


README

Latest Version Software License Build Status Coverage

PHP 实现的 测距算法。请参考 使用三个或更多点进行 WiFi 测距的指南

安装

使用 Composer 安装库。

$ composer require tuupola/trilateration

使用方法

纯 PHP 版本

纯 PHP 实现通过传统代数找到三个球面的交点来计算位置。如果球面不相交,算法会增大球面直到它们相交。

use Tuupola\Trilateration\Intersection;
use Tuupola\Trilateration\Sphere;

$sphere1 = new Sphere(60.1695, 24.9354, 81175);
$sphere2 = new Sphere(58.3806, 26.7251, 162311);
$sphere3 = new Sphere(58.3859, 24.4971, 116932);

$trilateration = new Intersection($sphere1, $sphere2, $sphere3);
$point = $trilateration->position();

print_r($point);

/*
Tuupola\Trilateration\Point Object
(
    [latitude:protected] => 59.418775152143
    [longitude:protected] => 24.753287172291
)
*/

$url = "https://appelsiini.net/circles/"
     . "?c={$sphere1}&c={$sphere2}&c={$sphere3}&m={$point}";

print '<a href="{$url}">Open in map</a>';

在地图上打开

R 语言的非线性最小二乘法

R 版本使用 非线性最小二乘拟合。它可以使用三个或更多位置进行计算,并在数据不够准确时给出更好的结果。在您使用此版本之前,必须安装 R 语言geosphere 包。

$ sudo yum -y install R
$ sudo su - -c "R -e \"install.packages('geosphere', repos='http://cran.rstudio.com/')\""
use Tuupola\Trilateration\NonLinearLeastSquares;
use Tuupola\Trilateration\Sphere;

$sphere1 = new Sphere(60.1695, 24.9354, 81175);
$sphere2 = new Sphere(58.3806, 26.7251, 162311);
$sphere3 = new Sphere(58.3859, 24.4971, 116932);

$trilateration = new NonLinearLeastSquares($sphere1, $sphere2, $sphere3);
$point = $trilateration->position();

print_r($point);

/*
Tuupola\Trilateration\Point Object
(
    [latitude:protected] => 59.4355408765689
    [longitude:protected] => 24.7747644991839

)
*/

$url = "https://appelsiini.net/circles/"
     . "?c={$sphere1}&c={$sphere2}&c={$sphere3}&m={$point}";

print '<a href="{$url}">Open in map</a>';

在地图上打开

测试

您可以手动或自动运行测试,每次代码更改时都自动进行测试。自动测试需要 entr 运行。

$ make test
$ brew install entr
$ make watch

贡献

请参阅 CONTRIBUTING 以获取详细信息。

安全性

如果您发现任何与安全相关的问题,请通过电子邮件 tuupola@appelsiini.net 而不是使用问题跟踪器进行报告。

许可证

MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件