I am trying to do basic binary line classification in PHP. (Programming language irrelevant, just more comfortable with PHP).
So basically I have 2 arrays of coordinates:
$classA = [ new Point(1,1), new Point(1,2), new Point(3,3), new Point(1,5) ];
$classB = [ new Point(4,1), new Point(5,2), new Point(4,1), new Point(6,6) ];
I need to iterate through these arrays and get 2 pairs of points each time (A pair consists of a point from classA and another from classB). It is important to get all possible combinations. Once a particular point is in a pair, it cannot be present in another pair.
For example the first two pairs would be:
$pair1 = [$a[0], $b[0]];
$pair2 = [$a[1], $b[1]];
To better explain myself, this is what I need:
When the first pair contains [1,1] , [4,1] all possibile combinations for the other pair are highlighted in yellow.
So far this is what I have:
$classA = [ new Point(1,1), new Point(1,2), new Point(3,3)];
$classB = [ new Point(4,1), new Point(5,2), new Point(4,1)];
$combinations = [];
$pair1 = [];
$pair2 = [];
$n = count($classA);
$m = count($classB);
for ($i=0; $i<$n; $i++){
for ($j=0; $j<$m; $j++){
$pair1 = [ $classA[$i], $classB[$j] ];
for ($z=0; $z<$n; $z++){
if($z != $i && $z != $j){
for ($y=0; $y<$m; $y++){
if($y != $i && $y != $j){
$pair2 = [ $classA[$z], $classB[$y] ];
$combinations[] = [$pair1, $pair2];
}
}
}
}
}
}
Apart from being inefficient, this is giving me many duplicates, is there a way to only get unique combinations?