python – 测量连续点的曲率

python – 测量连续点的曲率,第1张

概述我有一个点列表(数量级为数万),我需要使用 python识别两件事: 1-这些点中的连续点组(abs(x2-x1)< = 1和abs(y2-y1)< = 1) 2-每组的弧度/半径 以下是一组示例: [[331, 400], [331, 1200], [332, 400], [332, 486], [332, 522], [332, 655], [332, 1200], [332, 3800], 我有一个点列表(数量级为数万),我需要使用 python识别两件事:

1-这些点中的连续点组(abs(x2-x1)< = 1和abs(y2-y1)< = 1) 2-每组的弧度/半径 以下是一组示例:

[[331,400],[331,1200],[332,486],522],
655],3800],3877],3944],3963],
[332,3992],4050],[333,
560],588],655],700],
[333,[334,
400],558],586],654],
[334,697],
3963],[335,521],
[335,556],585],653],695],
3800],
4050],[336,520],555],584],
[336,651],693],
3944],[337,
[337,554],583],649],692],[338,377],553],582],
[338,647],691],[339,
[339,581],644],
654],690],706],[340,376],552],580],641],
[340,689],713],
3877],[341,
[341,579],
639],688],715],[342,
375],578],
[342,637],717],3858],3925],3954],4011],4107],[343,374],
[343,577],635],642],
687],718],[344,373],576],
[344,633],687],719],[345,372],
[345,575],630],720],[346,370],574],
[346,628],686],721],[347,368],
[347,572],626],
686],[348,366],487],570],
[348,624],[349,364],
[349,568],622],722],[350,362],619],
[350,
3858],
4107],[351,357],
[351,
1200],3819],
3915],3934],
4069],[352,355],
[352,621],3915],4069],[353,353],375],
[353,623],
642],
3992],[354,351],
[354,
625],3877]]

解决方法 这将为您提供群集和 list of angles:
from sklearn.cluster import DBSCANfrom scipy.spatial import distancefrom scipy.optimize import curve_fitimport numpy as np,mathdata = [[331,522]] #....def angle(pt1,pt2):    x1,y1 = pt1    x2,y2 = pt2    inner_product = x1*x2 + y1*y2    len1 = math.hypot(x1,y1)    len2 = math.hypot(x2,y2)    return math.acos(inner_product/(len1*len2))db=DBSCAN(eps=1,min_samples=2,metric='precomputed').fit(  distance.squareform(distance.pdist(data)))core_samples = db.core_sample_indices_labels = db.labels_n_clusters_ = len(set(labels)) - (1 if -1 in labels else 0)unique_labels = set(labels)for k in unique_labels:    class_members = [index[0] for index in np.argwhere(labels == k)]    cluster_core_samples = [index for index in core_samples                            if labels[index] == k]    curve = np.array([data[index] for index in class_members])    print k,curve,[angle(p1,p2) for p1,p2 in zip(curve,curve[1:])]
总结

以上是内存溢出为你收集整理的python – 测量连续点的曲率全部内容,希望文章能够帮你解决python – 测量连续点的曲率所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1205080.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-04
下一篇 2022-06-04

发表评论

登录后才能评论

评论列表(0条)

保存