divineomega / php-distance
允许计算点之间许多类型的距离
v1.0.1
2018-12-14 10:38 UTC
Requires
- php: >=7.0.0
This package is auto-updated.
Last update: 2024-08-29 05:06:23 UTC
README
PHP Distance 库允许计算点之间许多类型的距离。
安装
您可以使用 Composer 轻松安装 PHP Distance。只需从项目的根目录运行以下命令。
composer require divineomega/php-distance
如果您之前从未使用过 Composer 依赖管理器,请访问Composer 网站获取有关如何开始的信息。
用法
请参阅以下代码片段,展示如何使用此库。
$a = new Point($x1, $y1); $b = new Point($x2, $y2); $c = new Point($x3, $y3, $z3); # Infinite dimensions supported by some distance types $distanceType = new Euclidean(); $distanceType = new EuclideanSquare(); $distanceType = new Haversine(); # For GPS coordinates (latitude and longitude) $distance = (new Distance()) ->type(new Euclidean()) # Type is optional, and defaults to Euclidean distance ->from($a) ->to($b) ->get();