如何计算3D中两点之间的距离? [英] How to calculate distance between two points in 3D?

查看:523
本文介绍了如何计算3D中两点之间的距离?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个列表。每个列表都有三行。每个列表的坐标系从上到下为(x,y,z)。我尝试使用数组,但是没有用。这是我的代码。

 将numpy导入为np 
p1 = np.array([list(marker_11_x ['11 :-。X']),list(marker_11_y ['11:-。Y']),
list(marker_11_z ['11:-。Z'])])
p2 = np.array ([list(original_x ['13:-。X']),list(original_y ['13:-。Y']),
list(original_z ['13:-。Z'])))

squared_dist = np.sum((((p1 [0] -p2 [0])** 2+(p1 [1] -p2 [1])** 2+(p1 [3]- p2 [3])** 2),
轴= 0)
dist = np.sqrt(squared_dist)

列表A = [-232.34,-233.1,-232.44 ,-233.02,-232.47,-232.17,-232.6,-232.29,-231.65]
[-48.48,-49.48,-50.81,-51.42,-51.95,-52.25,-52.83,-53.63,-53.24 ]
[-260.77,-253.6,-250.25,-248.88,-248.06,-247.59,-245.82,-243.98,-243.76]

列表B = [-302.07,-302.13 ,-303.13,-302.69,-303.03,-302.55,-302.6,-302.46,-302.59]
[-1.73,-3.37,-4.92,-4.85,-5.61,-5.2,-5.91,-6.41 ,-7.4]
[-280.1,-273.02,-269.74,-268.32,-267.45,-267.22,-266.01,-264.79,-264.96]

TypeError追溯(最近一次通话最近)
pandas_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()



pandas_libs\hashtable_class_helper.pxi在pandas._libs.hashtable.Int64HashTable.get_item()



TypeError:必须为整数



在处理过程中上面的异常中,发生了另一个异常:



KeyError Traceback(最近一次通话)
in()
1 numpy作为np $ b导入$ b 2 p1 = np.array([list(marker_11_x ['11:-。X']),list(marker_11_y ['11:-。Y']),list(marker_11_z ['11:-。Z'] )])
----> 3 p2 = np.array([list(original_x ['13:-。X']),list(original_y ['13:-。Y']),list( original_z ['13:-。Z'])])
4
5 squared_dist = np.sum((((p1 [0] -p2 [0])** 2+(p1 [1] -p2 [1])** 2+(p1 [3] -p2 [3])** 2),轴= 0)



E:\ProgramData strongAnaconda3\lib\站点软件包\pandas\core\series.py,位于 getitem ((自身,密钥))
764 key = com._apply_if_callable(key,self)
765试试:
-> 766结果= self.index.get_value(self,key)
767
768如果不是is_scalar (结果):



E:\ProgramData\Anaconda3\lib\site-packages\pandas\core\indexes\base.py get_value(self,series,key)
3101试试:
3102 return self._engine.get_value(s,k,
-> 3103 tz = getattr(series.dtype,'tz', None))
3104,但KeyError为e1:如果len(self)> 0且self.inferred_type为['integer','boolean'],则为
3105:


$ b pandas._libs.index.IndexEngine.get_value()中的$ b

pandas_libs\index.pyx



pandas._libs.index中的pandas_libs\index.pyx .IndexEngine.get_value()



pandas_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()



KeyError:'13:-。X'

解决方案

d的公式也将像这样:

  def distance_finder(one,two):
[x1,y1,z1] =一个#第一坐标
[x2,y2,z2] =两个#第二坐标

return(((x2-x1)** 2 )+((y2-y1)** 2)+((z2-z1)** 2))**(1/2)


I have two lists. Each list has three lines. The coordinate system is (x,y,z) from up to down for each list. I tried to use array but it didn't work. Here are my codes.

import numpy as np
p1 = np.array([list(marker_11_x['11:-.X']), list(marker_11_y['11:-.Y']), 
list(marker_11_z['11:-.Z']) ])
p2 = np.array([list(original_x['13:-.X']), list(original_y['13:-.Y']), 
list(original_z['13:-.Z'])])

squared_dist = np.sum(((p1[0]-p2[0])**2+(p1[1]-p2[1] )**2+(p1[3]-p2[3] )**2), 
axis=0)
dist = np.sqrt(squared_dist)

list A = [-232.34, -233.1, -232.44, -233.02, -232.47, -232.17, -232.6, -232.29, -231.65]
[-48.48, -49.48, -50.81, -51.42, -51.95, -52.25, -52.83, -53.63, -53.24]
[-260.77, -253.6, -250.25, -248.88, -248.06, -247.59, -245.82, -243.98, -243.76]

List B = [-302.07, -302.13, -303.13, -302.69, -303.03, -302.55, -302.6, -302.46, -302.59]
[-1.73, -3.37, -4.92, -4.85, -5.61, -5.2, -5.91, -6.41, -7.4]
[-280.1, -273.02, -269.74, -268.32, -267.45, -267.22, -266.01, -264.79, -264.96]

TypeError Traceback (most recent call last) pandas_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()

TypeError: an integer is required

During handling of the above exception, another exception occurred:

KeyError Traceback (most recent call last) in () 1 import numpy as np 2 p1 = np.array([list(marker_11_x['11:-.X']), list(marker_11_y['11:-.Y']), list(marker_11_z['11:-.Z']) ]) ----> 3 p2 = np.array([list(original_x['13:-.X']), list(original_y['13:-.Y']), list(original_z['13:-.Z'])]) 4 5 squared_dist = np.sum(((p1[0]-p2[0])**2+(p1[1]-p2[1] )**2+(p1[3]-p2[3] )**2), axis=0)

E:\ProgramData\Anaconda3\lib\site-packages\pandas\core\series.py in getitem(self, key) 764 key = com._apply_if_callable(key, self) 765 try: --> 766 result = self.index.get_value(self, key) 767 768 if not is_scalar(result):

E:\ProgramData\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_value(self, series, key) 3101 try: 3102 return self._engine.get_value(s, k, -> 3103 tz=getattr(series.dtype, 'tz', None)) 3104 except KeyError as e1: 3105 if len(self) > 0 and self.inferred_type in ['integer', 'boolean']:

pandas_libs\index.pyx in pandas._libs.index.IndexEngine.get_value()

pandas_libs\index.pyx in pandas._libs.index.IndexEngine.get_value()

pandas_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()

KeyError: '13:-.X'

解决方案

The code and also the formula is gonna be like this :

def distance_finder(one,two) :
    [x1,y1,z1] = one  # first coordinates
    [x2,y2,z2] = two  # second coordinates

    return (((x2-x1)**2)+((y2-y1)**2)+((z2-z1)**2))**(1/2)

这篇关于如何计算3D中两点之间的距离?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆