# Nearest\_neighbor() and euclidean\_distance in Agents

**URL:** <https://discourse.julialang.org/t/nearest-neighbor-and-euclidean-distance-in-agents/115270>\
**Category:** Modelling & Simulations\
**Tags:** question, agents, modelling, eventqueueabm\
**Created:** [June 6, 2024, 8:42am UTC](https://discourse.julialang.org/t/nearest-neighbor-and-euclidean-distance-in-agents/115270 "2024-06-06T08:42:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sahil\_Khan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sahil_khan/32/47573_2.png) [@Sahil\_Khan](https://discourse.julialang.org/u/Sahil_Khan)\
**Post date:** [June 6, 2024, 8:42am UTC](https://discourse.julialang.org/t/nearest-neighbor-and-euclidean-distance-in-agents/115270/1 "2024-06-06T08:42:28Z")

</div>

Hey,

Im working with interaction\_pair() function which uses nearest\_neighbor() to find a pair. Now while applying this function I feel that doesn’t matter how small r value we give in `nearest_neighbor(model[2], model, 10^-100)` there is a limit and it finds neighbor based on that.

Euclidean distance output for neighbor :

```julia
julia> euclidean_distance(model[2].pos, nearest_neighbor(model[2], model, 10^-100).pos, model)
0.07715281063325427

```

Now this value is pretty big as compare to radius given in nearest\_neighbor fucntion. I will not expect it to find any neighbor based on that r value. Its just too small.

Im afraid that Im mixing different ideas here? does that r has any significance in that function ?

Thank you 🙂

---

<div class="post-metadata">

**Author:** ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Post date:** [June 6, 2024, 8:53am UTC](https://discourse.julialang.org/t/nearest-neighbor-and-euclidean-distance-in-agents/115270/2 "2024-06-06T08:53:17Z")

</div>

file a bug report with a reproducible MWE!

---

<div class="post-metadata">

**Author:** ![Sahil\_Khan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sahil_khan/32/47573_2.png) [@Sahil\_Khan](https://discourse.julialang.org/u/Sahil_Khan)\
**Post date:** [June 6, 2024, 9:15am UTC](https://discourse.julialang.org/t/nearest-neighbor-and-euclidean-distance-in-agents/115270/3 "2024-06-06T09:15:29Z")

</div>

Done. [Conflict between nearest\_neighbor() function and euclidean distance for agent pair. · Issue #1043 · JuliaDynamics/Agents.jl · GitHub](https://github.com/JuliaDynamics/Agents.jl/issues/1043)
