# Distance from fiducial to a plane

**URL:** <https://discourse.slicer.org/t/distance-from-fiducial-to-a-plane/18766>\
**Category:** Support\
**Tags:** 3d-model\
**Created:** [July 16, 2021, 12:28pm UTC](https://discourse.slicer.org/t/distance-from-fiducial-to-a-plane/18766 "2021-07-16T12:28:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![YingHsu](https://avatars.discourse-cdn.com/v4/letter/y/47e85d/32.png) [@YingHsu](https://discourse.slicer.org/u/YingHsu)\
**Post date:** [July 16, 2021, 12:28pm UTC](https://discourse.slicer.org/t/distance-from-fiducial-to-a-plane/18766/1 "2021-07-16T12:28:58Z")

</div>

1. I have a CBCT data, and I want to measure distance from a given fiducial to a plane. I tried extension of “Angle Planes”, but I could not add scene before continuing to manage planes.
2. Is there any extension for measuring the distance between a given fiducial to a plane?

Thank you in advance.

---

<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:** [July 16, 2021, 10:32pm UTC](https://discourse.slicer.org/t/distance-from-fiducial-to-a-plane/18766/2 "2021-07-16T22:32:32Z")

</div>

You can write a script easily that gets distances of points `F` from a plane `P` (by transforming the points to the plane’s coordinate system and get the third coordinate value):

```python
planeNode = getNode('P')
fiducialNode = getNode('F')

planeToWorld = vtk.vtkMatrix4x4()
planeNode.GetObjectToWorldMatrix(planeToWorld)
points_World = arrayFromMarkupsControlPoints(fiducialNode)
points_Plane = np.dot(np.linalg.inv(arrayFromVTKMatrix(planeToWorld)), np.append(points_World, np.ones([4,1]), axis=1).T)
distances = points_Plane[2]
print(distances)

```

---

<div class="post-metadata">

**Author:** ![Daniel1](https://avatars.discourse-cdn.com/v4/letter/d/b19c9b/32.png) [@Daniel1](https://discourse.slicer.org/u/Daniel1)\
**Post date:** [February 1, 2023, 11:10am UTC](https://discourse.slicer.org/t/distance-from-fiducial-to-a-plane/18766/3 "2023-02-01T11:10:50Z")

</div>

Hello Prof Lasso, I am interested in finding perpendicular distance from point F to plane P as well and unfortunately that bit of code did not work. Dan

---

<div class="post-metadata">

**Author:** ![Daniel1](https://avatars.discourse-cdn.com/v4/letter/d/b19c9b/32.png) [@Daniel1](https://discourse.slicer.org/u/Daniel1)\
**Post date:** [February 3, 2023, 9:59pm UTC](https://discourse.slicer.org/t/distance-from-fiducial-to-a-plane/18766/4 "2023-02-03T21:59:19Z")

</div>

I am using Slicer 5.2.1

After entering the code:  
import numpy as np  
planeNode = getNode(‘P’)  
fiducialNode = getNode(‘F’)  
planeToWorld = vtk.vtkMatrix4x4()  
planeNode.GetObjectToWorldMatrix(planeToWorld)  
points\_World = arrayFromMarkupsControlPoints(fiducialNode)  
points\_Plane = np.dot(np.linalg.inv(arrayFromVTKMatrix(planeToWorld)), np.append(points\_World, np.ones([4,1]), axis=1).T)  
distances = points\_Plane[2]  
print(distances)

I get the following error:  
File “”, line 7, in   
File “\< **array\_function** internals\>”, line 180, in append  
File “/Applications/Slicer.app/Contents/lib/Python/lib/python3.9/site-packages/numpy/lib/function\_base.py”, line 5444, in append  
return concatenate((arr, values), axis=axis)  
File “\< **array\_function** internals\>”, line 180, in concatenate  
ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 0, the array at index 0 has size 1 and the array at index 1 has size 4

How can this be fixed?
