Collision avoidance

I have spheres which are randomly generated on a grid. I want to know which of these spheres are within a certain distance from another sphere.

How can I go about doing this? I have read about collision detection but I don’t want to know when the spheres collide – only if they are close to each other. I later want to use this for collision avoidance.

Thank you.

So in other words, you want to get the length of the vector between the two position vectors:
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:math_for_dummies

For collision avoidance a keyword you will want to search is “steering”. There is some sample steering code in the jmonkeyplatform-contributions repo.