Skip to content
Advertisement

Eucledian distance to point source

I am stimulating a model via a point source, which is located above (z-direction)– to be able to compute the impact of the stimulation i need to compute the eucledian distance from this point power source to each mid of compartment (see picute).

I tried it this way, but the results are strange — maybe the computation of the distance is wrong…

x_Mid = np.zeros(nComp)
y_Mid = np.zeros(nComp)
z_Mid = np.zeros(nComp)
for i in range(0, nComp):
    y_Mid[i] = 0.
    if i == 0:
        x_Mid[i] = (lComp[i] / 2.)
        z_Mid[i] = 1*elecShift
        compDist[i] = distance.euclidean(x_Mid,y_Mid,z_Mid)*10**(-4)

    else:
        x_Mid[i] = x_Mid[i - 1] + (lComp[i - 1] / 2.) + (lComp[i] / 2.)
        z_Mid[i] = 1*elecShift
        compDist[i] = distance.euclidean(x_Mid,y_Mid,z_Mid)*10**(-4)

lcomp is the length of the compartment. y – direction is zero, because its a 2D Model. elecshift is the distance of the point source in z-direction and the units are micrometer (therefore then its multiplied by 10^-4 to give it in centimeter). nComp is the number of compartments.

Is the computation of the eucledean distance from the source to each compartment center correct?

pic1

Advertisement

Answer

I’m assuming the source is at [0, 0, 0].

You can calculate three vectors in a simpler way:

x_Mid = np.cumsum(lComp) - lComp / 2.
y_Mid = np.zeros_like(x_Mid)
z_Mid = elecShift * np.ones_like(x_Mid)

Then the simplest calculation of distance is just:

compDist = np.sqrt(x_Mid**2 + y_Mid**2 + z_Mid**2) * 1.e-4

or even:

compDist = np.sqrt(x_Mid**2 + elecShift**2) * 1.e-4

And if you want to use function from scipy, then according to API, use:

for i in range(0, nComp):
  compDist[i] = distance.euclidean([x_Mid[i], y_Mid[i], z_Mid[i]], 0.)*10**(-4)

Your code was providing current x_Mid as one point, y_Mid as second one and z_Mid as weights to distance.euclidean().

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement