# Distance Measurement Separated to 3 Axes

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).

Yours sincerely
Marton

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

1 Like

Dear chir.set,

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

Yours sincerely
Marton

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 :

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

The remaining questions will require more time.

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

``````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)
``````

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

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.

I tried but it does not work:

``````... 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)
``````

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

Funny output

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

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)

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

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 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