PHP 计算两点之间的距离以像素为单位
PHP Calc distance between two points result in pixels
假设我们有一个高 500 x 宽 500 像素的正方形
第一点位于 H311:W447
第二点位于 H65:W156
如何使用 PHP 计算这些点之间的像素距离?
你会使用 Pythagoras Theorem.
$dh = $h1 - $h2;
$dw = $w1 - $w2;
$dist = sqrt($dh*$dh + $dw*$dw);
请注意,您可能会得到非整数结果。
如果您对 Manhattan Distance 感兴趣,您可以
$dist = abs($h1 - $h2) + abs($w1 - $w2);
假设我们有一个高 500 x 宽 500 像素的正方形 第一点位于 H311:W447 第二点位于 H65:W156
如何使用 PHP 计算这些点之间的像素距离?
你会使用 Pythagoras Theorem.
$dh = $h1 - $h2;
$dw = $w1 - $w2;
$dist = sqrt($dh*$dh + $dw*$dw);
请注意,您可能会得到非整数结果。
如果您对 Manhattan Distance 感兴趣,您可以
$dist = abs($h1 - $h2) + abs($w1 - $w2);