2010-06-19 106 views
0

我有点A(x,y)和B(x,y)。他们列为数组(a => array(x,y),b => array(x,y))坐标系(PHP数组)

如何获得点A和B之间的距离。 :)

+0

这是Facebook的困惑?听起来像这样:P – 2010-06-19 13:20:21

回答

4

那么,记住你的高中几何。

r = square_root((x2 - x1)^2 + (y2 - y1)^2) 

所以在PHP中:

$dx = $points['b'][0] - $points['a'][0]; 
$dy = $points['b'][1] - $points['a'][1]; 
$r = sqrt(pow($dx, 2) + pow($dy, 2));