I'm working on a C# project to find the euclidean distance between 2 points.
Right now I have 2 for loops like this:
for (int i = 0; i < pregcount; i ++)
{
double dist_minima = double.MaxValue;
for (int j = 0; j < poiscount; j ++)
{
double distancia_cuadratica = Math.Pow(pois[j, 0] - preg[i, 0], 2) + Math.Pow(pois[j, 1] - preg[i, 1], 2) + Math.Pow(pois[j, 2] - preg[i, 2], 2);
}
}
preg and pois are array matrix of n elements (preg is 250 elements and pois is 900,000 elements Is there a way to make this faster? like a function in C# or a library that would just calculate the distance more quickly?
I take almost 2 minutes to complete the whole thing. The calculation inside the second loop is what takes all the time.