Hi Alexandru
I'm glad the code works for you, it should give you enough to develop and apply further and glad it helps, cheers for the thank you.
Regarding the DISTANCE function, yes........it's all about Pythagoras and the DISTANCE is usually the calculated hypotenuse of the volume.
Sorry, trouble getting correct symbols in.....
Hypotenuse (distance) =sqrt(Asq+Bsq)
Therefore, regarding your values (I have rounded them to integers).
x difference = 549 between pos[1] and pos[2]
y difference = 150 between pos[1] and pos[2]
z difference = 230 between pos[1] and pos[2]
So you have to calculate the hypotenuse between X and Y, then calculate the hypotenuse of the volume, using the calculated hypotenuse and the z difference.
H1 = sqrt(549sq+150sq)
H1 = sqrt(301401+22500)
H1 = sqrt(323901)
H1 = 569
H2 = sqrt(H1sq+230sq)
H2 = sqrt(323761+52900)
H2 = sqrt(377661)
H2 = 613.7 ( this is different as I have used integers - but you can see similar values).
H2 is the result of DISTANCE (pos[1],pos[2])
People assume it should be in x or y or z, but you have to remember there is volume between 2 points, therefore the DISTANCE will not provide matching results to x, y or z....
I hope I have explained it correctly for you to understand, let me know if not.