我想做一个简单的程序,我想顺时针排列我的坐标点
fourPointsCard.append(firstPoint)
fourPointsCard.append(secondPoint)
fourPointsCard.append(thirdPoint)
fourPointsCard.append(fourPoint)
我创建了一个包含我所有4点的列表,并给出下一个列表
fourPointsCard = [array([[508, 116]], dtype=int32), array([[351, 129]], dtype=int32), array([[371, 379]], dtype=int32), array([[527, 366]], dtype=int32)]
有没有办法顺时针或逆时针排列这些点
您的点似乎形成了一个凸面形状,这将允许此方法工作。简单地说,找到点的质心,然后找到从质心到每个点的夹角。基于此角度对点进行排序。我假设第一列是水平的,第二列是垂直的
arr
将包含NumPy数组中的原始点,而arr_sorted
将根据角度按升序对点进行排序。升序意味着您的点将按顺时针顺序排列。如果要逆时针排序,请使用ind = np.argsort(-angles)
在负上排序以下是订购前后的要点:
相关问题 更多 >
编程相关推荐