查找平面和直线之间的交点

问题描述

我试图找到一个对等的对象,但是我正在努力寻找解决问题的方法我有两条曲线定义为python中的2D列表。我想找到curve_1到curve_2的正交投影。 我开始这样的事情:

import numpy as np
import matplotlib.pyplot as plt
def unit_tangent_vector(curve):
    tangent_vectors = np.diff(curve,axis=0)
    unit_tangent_vectors = tangent_vectors / np.linalg.norm(tangent_vectors,axis=1)[:,None]
    return unit_tangent_vectors

curve_1 = np.array([[   0.,1050.45881  ]
 [  54.4012659,1050.45924  ]
 [ 108.772202,1050.46115  ]
 [ 163.063568,1050.46476  ]
 [ 217.210682,1050.47023  ]
 [ 271.123361,1050.47781  ]
 [ 324.675052,1050.48779  ]
 [ 377.692745,1050.50048  ]
 [ 427.845685,1053.07373  ]
 [ 461.323846,1068.71938  ]
 [ 494.723661,1084.33569  ]])
curve_2 = np.array([[   0.,1050.56801  ]
 [  51.8993183,1050.56801  ]
 [ 103.798637,1050.56801  ]
 [ 155.697955,1050.56801  ]
 [ 207.597273,1050.56801  ]
 [ 259.496592,1050.56801  ]
 [ 311.39591,1050.56801  ]
 [ 363.295228,1050.56801  ]
 [ 415.191677,1050.56813  ]
 [ 455.961611,1065.59296  ]
 [ 495.02527,1083.69965  ]])

curve_1_tangents = unit_tangent_vector(curve_1)
curve_1_tangents = np.vstack([curve_1_tangents,curve_1_tangents[-1]]) # Need to have the same number of values as the curve
curve_2_tangents = unit_tangent_vector(curve_2)
curve_2_tangents = np.vstack([curve_2_tangents,curve_2_tangents[-1]])

ndots = np.einsum('ij,ij->i',curve_1_tangents,curve_2_tangents)

w_vector = curve_2 - curve_1


si = -np.array([t_le.dot(w) for t_le,w in zip(curve_1,w_vector)]) / ndots

psi = w_vector + si[:,None]*curve_2_tangents+curve_1 # Intersections


ax = plt.figure().gca()

ax.plot(curve_1.T[0],curve_1.T[1],marker="o",color="blue")
ax.plot(curve_2.T[0],curve_2.T[1],color="red")
ax.scatter(psi.T[0],psi.T[1],marker="x",color="green")
n = 8
ax.quiver(curve_1[n][0],curve_1[n][1],curve_1_tangents[n][0],curve_1_tangents[n][1],color="grey")
ax.quiver(curve_2[n][0],curve_2[n][1],curve_2_tangents[n][0],curve_2_tangents[n][1])
plt.show()

但是,切线计算似乎不正确,并导致错误的结果。例如,如果我运行此代码,它将给我:

enter image description here

我的交点应该是青色。 可以说,灰色切向量是平面的法线。我想找到每个平面(在蓝色曲线的所有点)和红色曲线之间的交点。我不是在寻找两条曲线之间的交点。

基本上,此功能仅适用于一个平面和一条直线:

def find_intersection(plane_normal,plane_point,ray_direction,ray_point):
epsilon=1e-6
ndotu = plane_normal.dot(ray_direction) 

if abs(ndotu) < epsilon:
    print ("no intersection or line is within plane")

    w = ray_point - plane_point
    si = -plane_normal.dot(w) / ndotu
    Psi = w + si * ray_direction + plane_point #intersections

我只想将其扩展为包含多个点的numpy数组

感谢您的帮助

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)