# Kdtree returned indices and distances

**URL:** https://discourse.itk.org/t/kdtree-returned-indices-and-distances/3809
**Category:** Algorithms
**Created:** [January 29, 2021, 11:04am UTC](https://discourse.itk.org/t/kdtree-returned-indices-and-distances/3809 "2021-01-29T11:04:53Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![aestebanlansaque](https://discourse.itk.org/letter_avatar_proxy/v4/letter/a/dec6dc/32.png) [@aestebanlansaque](https://discourse.itk.org/u/aestebanlansaque)
#### Post date: [January 29, 2021, 11:04am UTC](https://discourse.itk.org/t/kdtree-returned-indices-and-distances/3809/1 "2021-01-29T11:04:53Z")

</div>

Good morning everyone,  
I am using itk::Statistics::KdTreeGenerator::KdTree in order to find correspondences but it looks like distances are not sorted and always one value is 0 (which might be true for few vertices).

For example:  
Point 4997 distances: 0.049331 0.043294 0 0.0407943 0.0460834  
Point 4998 distances: 0.035021 0 0.0539435 0.043294 0.0524717  
Point 4999 distances: 0 0.035021 0.045838 0.050482 0.0575521

Does this make any sense? Is the first index in the InstanceIdentifierVectorType the index to the closes point or do I need to look for the minimum value?

Thank you for the help in advance,  
Anto.
