<分区>
我需要以 AX+BY+CZ+D=0 的形式计算两个平面的交点,并以两个 (x,y,z) 点的形式得到一条直线。我知道如何计算,但我想避免发明自行车并使用有效且经过测试的东西。是否有任何图书馆已经实现了这个?尝试搜索 opencv 和 google,但没有成功。
<分区>
我需要以 AX+BY+CZ+D=0 的形式计算两个平面的交点,并以两个 (x,y,z) 点的形式得到一条直线。我知道如何计算,但我想避免发明自行车并使用有效且经过测试的东西。是否有任何图书馆已经实现了这个?尝试搜索 opencv 和 google,但没有成功。
最佳答案
我的 numpy
解决方案:
def plane_intersect(a, b):
"""
a, b 4-tuples/lists
Ax + By +Cz + D = 0
A,B,C,D in order
output: 2 points on line of intersection, np.arrays, shape (3,)
"""
a_vec, b_vec = np.array(a[:3]), np.array(b[:3])
aXb_vec = np.cross(a_vec, b_vec)
A = np.array([a_vec, b_vec, aXb_vec])
d = np.array([-a[3], -b[3], 0.]).reshape(3,1)
# could add np.linalg.det(A) == 0 test to prevent linalg.solve throwing error
p_inter = np.linalg.solve(A, d).T
return p_inter[0], (p_inter + aXb_vec)[0]
a, b = (1, -1, 0, 2), (-1, -1, 1, 3)
plane_intersect(a, b)
Out[583]: (array([ 0., 2., -1.]), array([-1., 1., -3.]))
一个测试,subs 点返回:
p1, p2 = plane_intersect(a, b)
a_vec, b_vec = np.array(a[:3]), np.array(b[:3])
(np.dot(p1, a_vec), np.dot(p2, a_vec), np.dot(p1, b_vec), np.dot(p2, b_vec))
Out[585]: (-2.0, -2.0, -3.0, -3.0)
关于python - python中的平面相交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48126838/