# Calculate the shortest distance of two model in mm

**URL:** <https://discourse.slicer.org/t/calculate-the-shortest-distance-of-two-model-in-mm/16832>\
**Category:** Development\
**Created:** [March 29, 2021, 8:29pm UTC](https://discourse.slicer.org/t/calculate-the-shortest-distance-of-two-model-in-mm/16832 "2021-03-29T20:29:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raj\_Kumar\_Ranabhat](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/raj_kumar_ranabhat/32/9857_2.png) [@Raj\_Kumar\_Ranabhat](https://discourse.slicer.org/u/Raj_Kumar_Ranabhat)\
**Post date:** [March 29, 2021, 8:29pm UTC](https://discourse.slicer.org/t/calculate-the-shortest-distance-of-two-model-in-mm/16832/1 "2021-03-29T20:29:33Z")

</div>

Hi Experts,

I would like to calculate the shortest distance(in mm) of two models using VTK based on the point coordinates of the two models. How should I proceed, Is there a sample python script to find the shortest distance?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [April 3, 2021, 3:01am UTC](https://discourse.slicer.org/t/calculate-the-shortest-distance-of-two-model-in-mm/16832/2 "2021-04-03T03:01:29Z")

</div>

Completely different algorithms are used depending on how close the models are and if they are overlapping or not.

If models mostly overlap and there are only small differences between them then you can use ModelToModelDistance extension to compute distance between the models and then get the point corresponding to the shortest distance.

For models that do not overlap and far away from each other you may find the closest point by a few iterations of finding closest point of mesh A to a randomly selected point of mesh B, then find the closest point in mesh B to that point of mesh A, etc. You can use `FindClosestPoint` method of any locator (vtkPointLocator, vtkCellLocator) to get closest point position on a mesh.
