简体   繁体   English

到点源的欧几里德距离

[英]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).我正在通过位于上方(z 方向)的点源刺激 model——为了能够计算刺激的影响,我需要计算从该点电源到隔间每个中间的欧几里德距离(见图片)。

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. lcomp是隔间的长度。 y - direction is zero, because its a 2D Model. y - 方向为零,因为它是 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). elecshift是点源在 z 方向上的距离,单位是微米(因此,它乘以 10^-4,以厘米为单位)。 nComp is the number of compartments. nComp是隔间的数量。

Is the computation of the eucledean distance from the source to each compartment center correct?从源到每个隔间中心的欧氏距离的计算是否正确?

图1

I'm assuming the source is at [0, 0, 0] .我假设源位于[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:如果你想从 scipy 使用 function ,那么根据 API ,使用:

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() .您的代码将当前x_Mid作为一个点, y_Mid作为第二个点, z_Mid作为distance.euclidean()的权重。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM