我是靠谱客的博主 整齐钢笔,最近开发中收集的这篇文章主要介绍python直线交点数量,python中多条直线的最近交点,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

这是我最后使用的代码。感谢kevinkayaks和其他回应的人!非常感谢你的帮助!!!在

此函数的前半部分只是将点和角度的两个集合转换为方向向量。我相信剩下的基本上和埃里克和尤金的提议是一样的。我只是碰巧在Kevin's上取得了成功,并一直坚持到它对我来说是一个端到端的解决方案。在import numpy as np

def LS_intersect(p0,a0,p1,a1):

"""

:param p0 : Nx2 (x,y) position coordinates

:param p1 : Nx2 (x,y) position coordinates

:param a0 : angles in degrees for each point in p0

:param a1 : angles in degrees for each point in p1

:return: least squares intersection point of N lines from eq. 13 in

http://cal.cs.illinois.edu/~johannes/research/LS_line_intersect.pdf

"""

ang = np.concatenate( (a0,a1) ) # create list of angles

# create direction vectors with magnitude = 1

n = []

for a in ang:

n.append([np.cos(np.radians(a)), np.sin(np.radians(a))])

pos = np.concatenate((p0[:,0:2],p1[:,0:2])) # create list of points

n = np.array(n)

# generate the array of all projectors

nnT = np.array([np.outer(nn,nn) for nn in n ])

ImnnT = np.eye(len(pos[0]))-nnT # orthocomplement projectors to n

# now generate R matrix and q vector

R = np.sum(ImnnT,axis=0)

q = np.sum(np.array([np.dot(m,x) for m,x in zip(ImnnT,pos)]),axis=0)

# and solve the least squares problem for the intersection point p

return np.linalg.lstsq(R,q,rcond=None)[0]

#sample data

pa = np.array([[-7.07106638, 7.07106145, 1. ],

[-7.34817263, 6.78264524, 1. ],

[-7.61354115, 6.48336347, 1. ],

[-7.86671133, 6.17371816, 1. ],

[-8.10730426, 5.85419995, 1. ]])

paa = [-44.504854321138524, -42.02922380123842, -41.27857390748773, -37.145774853341386, -34.097022454778674]

pb = np.array([[-8.98220431e-07, -1.99999962e+01, 1.00000000e+00],

[ 7.99789129e-01, -1.99839984e+01, 1.00000000e+00],

[ 1.59830153e+00, -1.99360366e+01, 1.00000000e+00],

[ 2.39423914e+00, -1.98561769e+01, 1.00000000e+00],

[ 3.18637019e+00, -1.97445510e+01, 1.00000000e+00]])

pba = [88.71923357743934, 92.55801427272372, 95.3038321024299, 96.50212060095349, 100.24177145619092]

print("Should return (-0.03211692, 0.14173216)")

solution = LS_intersect(pa,paa,pb,pba)

print(solution)

最后

以上就是整齐钢笔为你收集整理的python直线交点数量,python中多条直线的最近交点的全部内容,希望文章能够帮你解决python直线交点数量,python中多条直线的最近交点所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(48)

评论列表共有 0 条评论

立即
投稿
返回
顶部