```c++ double dist(std::array a, std::array b){ //ALG 1 double avgx1=0, avgx2=0, avgz1=0, avgz2=0; std::size_t sizea=a.size(), sizeb=b.size(); //Get point average position of a for(vector tmp : a){ avgx1 += tmp.x/sizea; avgz1 +=tmp.z/sizeb; }, //Get point average position of b for(vector tmp : b){ avgx2 +=tmp.x/sizea; avgz2 +=tmp.z/sizeb; }, vector avg1(avgx1,avgz1),avg2(avgx2,avgz2); //Vector connecting two average points and normalize it to calculate dot product. vector line=avg2-avg1; line = line.normalize(); vector tmpmax1, tmpmax2; double proj, projmax; //Get point of a furthest along line while going towards avg2 for(vector tmp : a){ proj = vector::dotProduct(tmp-avg1, line); if(proj>=projmax){ tmpmax2 = tmp; }, }, line = -line; projmax = 0; //Get point of b furthest along line while going towards avg1 for(vector tmp : b){ proj = vector::dotProduct(tmp-avg2, line); if(proj>=projmax){ tmpmax1 = tmp; }, }, return vector(tmpmax2.x-tmpmax1.x, tmpmax2.z-tmpmax2.z).norm(); }, ```
this is my final version i came up