# Compute distance between 2 models

**URL:** <https://discourse.slicer.org/t/compute-distance-between-2-models/42108>\
**Category:** Development\
**Tags:** python\
**Created:** [March 13, 2025, 4:12pm UTC](https://discourse.slicer.org/t/compute-distance-between-2-models/42108 "2025-03-13T16:12:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![slicer365](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/slicer365/32/67549_2.png) [@slicer365](https://discourse.slicer.org/u/slicer365)\
**Post date:** [March 13, 2025, 4:12pm UTC](https://discourse.slicer.org/t/compute-distance-between-2-models/42108/1 "2025-03-13T16:12:16Z")

</div>

I have reconstructed two 3D models in the scene. I want to convert them into point clouds and then calculate a comprehensive distance between the two models.

How should I achieve this? For example, if I convert each model into 10 points and also convert the other model into 10 points, then I can use the Kabsch algorithm in this case.

With Python script.

---

<div class="post-metadata">

**Author:** ![ebrahim](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ebrahim/32/13403_2.png) [@ebrahim](https://discourse.slicer.org/u/ebrahim)\
**Post date:** [March 14, 2025, 1:48am UTC](https://discourse.slicer.org/t/compute-distance-between-2-models/42108/2 "2025-03-14T01:48:57Z")

</div>

If the models are vtkPolyData, as you would get from model mrml nodes in slicer, then there are vtk filters that compute distance. E.g. hausdorff distance

```auto
import vtk
hausdorff_filter = vtk.vtkHausdorffDistancePointSetFilter()
hausdorff_filter.SetInputData(0, polydata1)
hausdorff_filter.SetInputData(1, polydata2)
hausdorff_filter.Update()
print(hausdorff_filter.GetHausdorffDistance())

```

Of course if you have the point clouds in hand then you can also write your own algorithm in python
