tuupola / trilateration
Trilateration for PHP
Fund package maintenance!
tuupola
Requires
- nubs/vectorix: ^1.1
- symfony/process: ^3.3|^4.0
Requires (Dev)
- overtrue/phplint: ^0.2.0
- phpunit/phpunit: ^5.7
- squizlabs/php_codesniffer: ^2.5
This package is auto-updated.
Last update: 2024-11-29 05:35:58 UTC
README
PHP implementation of Trilateration algorithm. See Wifi Trilateration With Three or More Points for walkthrough.
Install
Install the library using Composer.
$ composer require tuupola/trilateration
Usage
Pure PHP Version
Pure PHP implementation calculates the position by finding the intersection of three spheres using traditional algebra. If the spheres do not intersect algorithm enlarges the spheres until they do intersect.
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>';
Non Linear Least Squares Using R
R version uses non linear least squares fitting. It can use three or more locations for the calculation and gives better results when given data is less accurate. Before using this version you must install the R language and geosphere package.
$ 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>';
Testing
You can run tests either manually or automatically on every code change. Automatic tests require entr to work.
$ make test
$ brew install entr $ make watch
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email tuupola@appelsiini.net instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.