Here I have written simple program but I have little issue in managing it.
I have 6 points, for each point I want to calculate distance to other points.
DEmo - http://ideone.com/mYl30O
code:
<?php
$a_points = array(
array(0, -1),
array(-2, 3),
array(4, 0),
array(3, 1),
array(5, 2),
array(0, 1),
);
$k = 0;
$a_sum_dists = array();
$sum = array();
foreach ($a_points as $i => $pt1) {
list($x1, $y1) = $pt1;
//$sum = 0;
foreach ($a_points as $j => $pt2) {
if ($j == $i) continue;
list($x2, $y2) = $pt2;
$sum[$k] = pow($x2- $x1, 2) + pow($y2- $y1, 2);
$k++;
}
//$a_sum_dists[$i] = $sum;
}
?>
What I want:
for each point, get distance to all other points. Then print point which is at min distance. If more then one such points, print all
Now we have min distance points for each point. So now prints points which appears most frequently as a min distance. If more then one such points, print all
sqrt(pow($x2- $x1, 2) + pow($y2- $y1, 2)), also I believe if you want to know the points used for specific sums a counter is not the best way.