我正在努力寻找用python编写问题代码的解决方案。 我有这些红色和蓝色的曲线(它们只是python中的点列表)。我想找到红线上的紫色点。
所以我认为解决这个问题的方法是找到与每个红点之间的直线相交的点,以及蓝线的每个点处由切线向量形成的平面:
问题是,当我试图用python为列表中的每个点求解这个简单的等式时,我最终发现绿点的位置不正确。 这是我的密码:
blue_curve = [[0.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]]
red_curve = [[0.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]]
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
blue_curve_tangents = unit_tangent_vector(blue_curve)
blue_curve_tangents = np.vstack([blue_curve_tangents, blue_curve_tangents[-1]])
red_curve_tangents = unit_tangent_vector(red_curve)
red_curve_tangents = np.vstack([red_curve_tangents,red_curve_tangents[-1]])
n_dot_u = np.einsum('ij,ij->i', blue_curve_tangents, red_curve_tangents)
n_dot_a = np.einsum('ij,ij->i', blue_curve_tangents,blue_curve)
n_dot_b = np.einsum('ij,ij->i', blue_curve_tangents,red_curve)
intersections = red_curve + (n_dot_a[:,None]-n_dot_b[:,None])/(n_dot_u[:,None])*red_curve_tangents
知道我做错了什么吗
谢谢
干杯
您的数学是正确的,检查正交性可得出:
我想问题在于你的情节的比例。
x axis
从[0, 500]
开始,而y axis
从[1050.45, 1050.56]
开始。因此,您手工绘制的直角不正确,因为轴不在ratio 1:1
中。交叉线看起来是笔直的,而实际上它们是略微成角度的例如,如果通过因子
1/1000
缩放x轴,使两个比例更相似,则生成的图像看起来与预期的一样:相关问题 更多 >
编程相关推荐