# Distance between two segments

**URL:** <https://discourse.slicer.org/t/distance-between-two-segments/4910>\
**Category:** Support\
**Created:** [November 29, 2018, 2:25pm UTC](https://discourse.slicer.org/t/distance-between-two-segments/4910 "2018-11-29T14:25:57Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [November 29, 2018, 8:53pm UTC](https://discourse.slicer.org/t/distance-between-two-segments/4910/5 "2018-11-29T20:53:33Z")

</div>

> [@torquil](#):
>
> What I want is the smallest possible distance

Yes this is why I wrote that you’ll need the minimum Hausdorff, which will be the distance between the two closest points. As @lassoan says it’s usually 0 because usually we compare two segments representing the same objects (so they overlap). So this is why it’s not shown in Segment Statistics UI (I thought for some reason that it was). I’m not aware of any method for getting this number on the UI, but this is some python code that will get it for you:

```
import vtkSlicerSegmentComparisonModuleLogicPython
s=getNode('vtkMRMLSegmentationNode1') # Whatever your input is
p1=s.GetClosedSurfaceRepresentation('Segment_1') # Again, depends on your input. If it's not a segmentation then you'll need to access the model nodes
p2=s.GetClosedSurfaceRepresentation('Segment_2')
pdf=vtkSlicerSegmentComparisonModuleLogicPython.vtkPolyDataDistanceHistogramFilter()
pdf.SetInputReferencePolyData(p1)
pdf.SetInputComparePolyData(p2)
pdf.Update()
pdf.GetNthPercentileHausdorffDistance(0)

```

---

_[View the full topic](https://discourse.slicer.org/t/distance-between-two-segments/4910)._
