in ix - selected panel
in d - direction
out iy - neigboar
dir[3]={cos(d),sin(d),0.0};
for (dd=0.0,iy=-1,i=0;i<n;i++) // all panels
if (i!=ix) // except self
if (panel[ix].rotation == panle[i].rotation) // test only same oriented
{
d0=dot(panel[i].position-panel[ix].position,dir); // distance of i from ix
if ((i<0)||(dd>d){ dd=d0; iy=i; } // remember closest
}
// here iy is closest neighbor to ix