I am writting a code for eliminating or making zero those spheres defined by coordinates (xcentro, ycentro, zcentro) whish overlap somewhere. The radius of each sphere is in vector r. However, the code is not efficient enough and I need some help to optimize it. The code is the following:
vector<double> xcentro, ycentro, zcentro, r;
#pragma omp parallel for num_threads(4)
for(int i=0; i<r.size()-1; i++)
{
for(int j=0; j<r.size()-1; j++)
{
//d.insert(d.begin() + i, sqrt(pow(xcentro[i] - xcentro[j], 2) + pow(ycentro[i] - ycentro[j], 2) + pow(zcentro[i] - zcentro[j], 2)));
d[i] = sqrt(pow(xcentro[i] - xcentro[j], 2) + pow(ycentro[i] - ycentro[j], 2) + pow(zcentro[i] - zcentro[j], 2));
if ((d[i] < (r[i] + r[j])) && (r[i] >= r[j])&&(i!=j))
{
//hacer 0 la esfera j-esima
r[j] = 0.0;
xcentro[j] = 0.0;
ycentro[j] = 0.0;
zcentro[j] = 0.0;
cout << "a" << endl;
}
else if ((d[i] < (r[i] + r[j])) && (r[i] < r[j]))
{
//hacer 0 la esfera i-esima
r[i] = 0.0;
xcentro[i] = 0.0;
ycentro[i] = 0.0;
zcentro[i] = 0.0;
cout << "b" << endl;
}
else
{
cout << "c" << endl;
}
cout << "i: " << i << "j: " << j << endl;
}
}
any help? And how can I delete then the elements whose radius is 0?