Euclidean distance between two three-dimensional points:
float deltaX = x1 - x0; float deltaY = y1 - y0; float deltaZ = z1 - z0; float distance = (float) Math.Sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ);
And in N dimensions (untested and vulnerable to overflow):
float DistanceN(float[] first, float[] second) { var sum = first.Select((x, i) => (x - second[i]) * (x - second[i])).Sum(); return Math.Sqrt(sum); }
Edit: I prefer the Zip
solution posted by dasblinkenlight below!
Ron warholic
source share