# Cross-hemispheric Euclidean distance w/ SurfDist

Hello,

I want to find the Euclidean distance between a node in one hemisphere and the location of every surface node in both hemispheres.

For example, for node 105 in the left hemisphere, I want to know how far this is from every node in the right hemisphere and left hemisphere of the pial surface. I am using this command:

``````
SurfDist -I std.141.\${hemisphere}.pial.gii -from_node 105L -input nodes.1D -Euclidean

``````

Nodes.1D is a list of number [0,198812). When \$hemisphere is set to “lh” vs. “rh”, I get different output distances, but I am concerned that the function is ignoring the L in “from_node 105L” and just looking at the distances between node 105 to every other node within each hemisphere’s surface. How can I find euclidean distances across the hemisphere?

Thanks!

Hi-

For SurfDist, I don’t think you can find cross-hemispheric distances. Each hemisphere is a separate mesh. There isn’t a principled way to “hop” between meshes, as far as I know.

To calculate distances between nodes within a given hemisphere is doable. Here is an AFNI Academy video playlist about calculating distances between/among nodes, part of the SUMA playlist (there are links to scripts if you expand the section just below the video):

–pt

While it’s hard to say how one might come up with a geodesic distance, you can compute a euclidean distance pretty simply. It’s just a distance between two xyz coordinates with sqrt((x1-x2)^2+(y1-y2)^2+(z1-z2)^2). You only need to put the coordinates of interest into a file for each surface.

If you want all distances between every pair, then use 1d_tool.py -show_distmat. This works well for a reasonably short list of coordinates.

You can get the coordinates for each surface, and then compute distances from selected ones to the other. Extract surface node coordinates in the ways shown here:

Ah, I see, I misread the question; it isn’t concerned with distance constrained along the surface mesh, just the “as a crow flies”* distance between two points ?

–pt

• NB: this is not a recommendation to have birds fly within someone’s cortex.

That’s right. It is a fairly simple problem. Just to make this a little simpler, here is an example of one way to compute the euclidean distance within AFNI. The distance is computed pairwise from two 1D text files each with 3 columns of x,y,z coordinates. You would have to duplicate the rows in one of these files to find distance to a single xyz coordinate.

# create some sample coordinates

echo “1 2 3” > testxyz1.1D
echo “3 2 3” > testxyz2.1D

# compute distance between each pair

1deval -a testxyz1.1D’’ -b testxyz1.1D’’ -c testxyz1.1D’’
-d testxyz2.1D’’ -e testxyz2.1D’’ -f testxyz2.1D’'.
-expr ‘sqrt((a-d)^2 + (b-e)^2 + (c-f)^2)’ |& tee dist_crow.1D
2

Thanks for the help! I ended up using “SurfMeasures -func coord_A” to retrieve the coordinates for every node in both hemispheres. Then, I wrote a python script to find all of the Euclidean distances that I needed. I appreciate your responsiveness.