# Distance Measurement Separated to 3 Axes

**URL:** <https://discourse.slicer.org/t/distance-measurement-separated-to-3-axes/25724>\
**Category:** Support\
**Created:** [October 16, 2022, 6:19pm UTC](https://discourse.slicer.org/t/distance-measurement-separated-to-3-axes/25724 "2022-10-16T18:19:49Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marci](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@Marci](https://discourse.slicer.org/u/Marci)\
**Post date:** [October 16, 2022, 6:19pm UTC](https://discourse.slicer.org/t/distance-measurement-separated-to-3-axes/25724/1 "2022-10-16T18:19:49Z")

</div>

Dear Slicer Community,

is it possible to measure the distance between two fiducials separated to the three main axes (frontal, sagittal, axial)? I not only need the exact distance (hypotenuse of a right triangle) between the two points, but also would like to know the distance projection according to the 3 axes (legs of a right triangle).

Thanks in advance,

Yours sincerely  
Marton

---

<div class="post-metadata">

**Author:** ![chir.set](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chir.set/32/66982_2.png) [@chir.set](https://discourse.slicer.org/u/chir.set)\
**Post date:** [October 17, 2022, 9:01am UTC](https://discourse.slicer.org/t/distance-measurement-separated-to-3-axes/25724/2 "2022-10-17T09:01:11Z")

</div>

Can you make one or two sketchy drawings of what you’re contemplating ? It’s hard to fully understand your goals.

---

<div class="post-metadata">

**Author:** ![Marci](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@Marci](https://discourse.slicer.org/u/Marci)\
**Post date:** [October 17, 2022, 9:29am UTC](https://discourse.slicer.org/t/distance-measurement-separated-to-3-axes/25724/3 "2022-10-17T09:29:50Z")

</div>

![IMG_0488](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/5/d/5dcd68fbab60a6315b4afa143ef57769fafa7f05.jpeg)

---

<div class="post-metadata">

**Author:** ![Marci](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@Marci](https://discourse.slicer.org/u/Marci)\
**Post date:** [October 17, 2022, 9:30am UTC](https://discourse.slicer.org/t/distance-measurement-separated-to-3-axes/25724/4 "2022-10-17T09:30:46Z")

</div>

Dear chir.set,

thank you for your response, hopefully I can better explain my problem with the sketch.

Yours sincerely  
Marton

---

<div class="post-metadata">

**Author:** ![chir.set](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chir.set/32/66982_2.png) [@chir.set](https://discourse.slicer.org/u/chir.set)\
**Post date:** [October 17, 2022, 10:56am UTC](https://discourse.slicer.org/t/distance-measurement-separated-to-3-axes/25724/5 "2022-10-17T10:56:22Z")

</div>

Your sketch is very clear, I grant that the drawn orthogonal axes are those of the 3D view without any rotation.

Calculating the distance between the 2 points is quite straightforward :

```auto
import math
lineLength = math.sqrt(vtk.vtkMath().Distance2BetweenPoints(p1, p2))

```

The remaining questions will require more time.

---

<div class="post-metadata">

**Author:** ![chir.set](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chir.set/32/66982_2.png) [@chir.set](https://discourse.slicer.org/u/chir.set)\
**Post date:** [October 17, 2022, 11:51am UTC](https://discourse.slicer.org/t/distance-measurement-separated-to-3-axes/25724/6 "2022-10-17T11:51:22Z")

</div>

This code snippet should answer your questions, as far as calculating distances is concerned.

```auto
import math

fiducialNode = slicer.util.getNode("ForumProblem")
p1 = fiducialNode.GetNthControlPointPositionWorld(0)
p2 = fiducialNode.GetNthControlPointPositionWorld(1)

# Put p1 at origin. rp2 is p2 relative to p1
rp2 = (p2[0] - p1[0], p2[1] - p1[1], p2[2] - p1[2])

b = abs(rp2[0]) # LeftRight
a = abs(rp2[1]) # AnteriorPosterior
d = abs(rp2[2]) # InferiorSuperior

e = math.sqrt(vtk.vtkMath().Distance2BetweenPoints(p1, p2))

# Check
c1 = math.sqrt( (a * a) + (b * b) )
c2 = math.sqrt( (e * e) - ( d * d ) )
print(c1, c2)

```

---

<div class="post-metadata">

**Author:** ![Marci](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@Marci](https://discourse.slicer.org/u/Marci)\
**Post date:** [October 17, 2022, 1:10pm UTC](https://discourse.slicer.org/t/distance-measurement-separated-to-3-axes/25724/7 "2022-10-17T13:10:54Z")

</div>

Thank you. I copied this into the Python Interactor it shows error unfortunately. What is the problem?

---

<div class="post-metadata">

**Author:** ![chir.set](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chir.set/32/66982_2.png) [@chir.set](https://discourse.slicer.org/u/chir.set)\
**Post date:** [October 17, 2022, 1:37pm UTC](https://discourse.slicer.org/t/distance-measurement-separated-to-3-axes/25724/8 "2022-10-17T13:37:50Z")

</div>

> [@chir.set](#):
>
> `ForumProblem`

You should create a Fiducial node with 2 points.  
Either you rename the fiducial node to ‘ForumProblem’, or you change this identifier in the code snippet to your fiducial node’s display name, typically ‘F’.

And it’s always a good idea to post error messages when requesting help.

---

<div class="post-metadata">

**Author:** ![Marci](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@Marci](https://discourse.slicer.org/u/Marci)\
**Post date:** [October 17, 2022, 1:54pm UTC](https://discourse.slicer.org/t/distance-measurement-separated-to-3-axes/25724/9 "2022-10-17T13:54:45Z")

</div>

I tried but it does not work:

```auto
... import math
File "<console>", line 7
import math
^
SyntaxError: invalid syntax
>>>
>>>
>>>
>>> fiducialNode = slicer.util.getNode("F”)
File "<console>", line 1
fiducialNode = slicer.util.getNode("F”)
^
SyntaxError: EOL while scanning string literal
>>>
>>> p1 = fiducialNode.GetNthControlPointPositionWorld(0)
Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'fiducialNode' is not defined
>>>
>>> p2 = fiducialNode.GetNthControlPointPositionWorld(1)
Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'fiducialNode' is not defined
>>>
>>>
>>>
>>> # Put p1 at origin. rp2 is p2 relative to p1
>>>
>>> rp2 = (p2[0] - p1[0], p2[1] - p1[1], p2[2] - p1[2])
Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'p2' is not defined
>>>
>>>
>>>
>>> b = abs(rp2[0]) # LeftRight
Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'rp2' is not defined
>>>
>>> a = abs(rp2[1]) # AnteriorPosterior
Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'rp2' is not defined
>>>
>>> d = abs(rp2[2]) # InferiorSuperior
Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'rp2' is not defined
>>>
>>>
>>>
>>> e = math.sqrt(vtk.vtkMath().Distance2BetweenPoints(p1, p2))
Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'p1' is not defined
>>>
>>>
>>>
>>> # Check
>>>
>>> c1 = math.sqrt( (a * a) + (b * b) )
Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'a' is not defined
>>>
>>> c2 = math.sqrt( (e * e) - ( d * d ) )
Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'e' is not defined
>>>
>>> print(c1, c2)

```

---

<div class="post-metadata">

**Author:** ![Marci](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@Marci](https://discourse.slicer.org/u/Marci)\
**Post date:** [October 17, 2022, 1:55pm UTC](https://discourse.slicer.org/t/distance-measurement-separated-to-3-axes/25724/10 "2022-10-17T13:55:36Z")

</div>

First I imported a CT. On the CT I defined two points, namely F1 and F2 as fiducials.

---

<div class="post-metadata">

**Author:** ![chir.set](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chir.set/32/66982_2.png) [@chir.set](https://discourse.slicer.org/u/chir.set)\
**Post date:** [October 17, 2022, 2:14pm UTC](https://discourse.slicer.org/t/distance-measurement-separated-to-3-axes/25724/11 "2022-10-17T14:14:37Z")

</div>

Funny output 🙂

What version of Slicer are you using ? It should work with stable or latest preview on any OS.

---

<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:** [October 17, 2022, 2:29pm UTC](https://discourse.slicer.org/t/distance-measurement-separated-to-3-axes/25724/12 "2022-10-17T14:29:55Z")

</div>

Just resolved it. There were a few issues:

- Quote characters were not good in the getNode call
- Method of getting control point position was not correct (expects two arguments in 4.11)

---

<div class="post-metadata">

**Author:** ![Marci](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@Marci](https://discourse.slicer.org/u/Marci)\
**Post date:** [October 18, 2022, 3:40pm UTC](https://discourse.slicer.org/t/distance-measurement-separated-to-3-axes/25724/13 "2022-10-18T15:40:48Z")

</div>

Dear chir.set,  
dear Csaba

thanks again for your fast response and help! It works all very well. Have a nice day!

Yours sincerely  
Marton

---

<div class="post-metadata">

**Author:** ![hedmondjohn](https://avatars.discourse-cdn.com/v4/letter/h/258eb7/32.png) [@hedmondjohn](https://discourse.slicer.org/u/hedmondjohn)\
**Post date:** [December 27, 2022, 7:28am UTC](https://discourse.slicer.org/t/distance-measurement-separated-to-3-axes/25724/14 "2022-12-27T07:28:10Z")

</div>

> [@Marci](#):
>
> `SyntaxError: EOL while scanning string literal`

An EOL ( End of Line ) error indicates that the Python interpreter expected a particular character or set of characters to have occurred in a specific line of code, but that those characters were not found before the end of the line . This results in Python stopping the program execution and throwing a syntax error .

The SyntaxError: EOL while [scanning string literal](http://net-informations.com/python/err/eol.htm) error in python occurs when while scanning a string of a program the python hit the end of the line due to the following reasons:

- Missing quotes
- Strings spanning multiple lines
