Python 在地图上找到一条线以下的所有点

Python 在地图上找到一条线以下的所有点,python,matplotlib,computational-geometry,cross-product,Python,Matplotlib,Computational Geometry,Cross Product,为了在具有多个点(近两千个点)的地图上绘制两点之间的路径,我使用以下函数: def path_between_cities(self, cities_with_coordinates, from_to): from matplotlib.lines import Line2D # coordinates from chosen path x = [int(from_to[0][2]), int(from_to[1][2])]

为了在具有多个点(近两千个点)的地图上绘制两点之间的路径,我使用以下函数:

def path_between_cities(self, cities_with_coordinates, from_to):

        from matplotlib.lines import Line2D     

        # coordinates from chosen path
        x = [int(from_to[0][2]), int(from_to[1][2])]
        y = [int(from_to[0][1]), int(from_to[1][1])]

        #create line
        line = Line2D(x,y,linestyle='-',color='k')

        # create axis
        x_ = np.array((0,2000))
        y_ = np.array((0,6000))

        plt.plot(x_,y_, 'o')

        for item in cities_with_coordinates:
            name = item[0]
            y_coord = int(item[1])
            x_coord = int(item[2])
            plt.plot([x_coord], [y_coord], marker='o', markersize=1, color='blue')
            plt.axes().add_line(line)

        plt.axis('scaled')
        plt.show()
我的目标是提取绘制线下方的所有点(坐标)

我知道你可以使用


给定大量向量,在上面的上下文中实现这一点的最有效方法是什么?

每个叉积操作仍然是
O(1)
。您可以对所有点运行下面的函数,并查看其中哪些点在下面,从而进行线性时间检查

def ccw(a,b,c):
    """ Returns 1 if c is above directed line ab else returns -1"""
    return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y)
    #a and b are the vertices and c is the test point.

除非您有关于这些点的其他信息,否则您必须检查每个点,以查看其是否位于特定线下

您的问题实际上与matplotlib或绘图无关。您有一个点数组和一条由两点定义的线。这是一个典型的计算几何问题。它可以单独使用NumPy来解决(因为您使用它)。我是否说过该问题取决于
matplotlib
plotting
?是的-通过使用
matplotlib
标记它。它指的是matplotib,因此是标记。在实际问题中,我使用“上下文”一词,它指的是matplotlib。不管怎样,很抱歉误导了你,先生。看看能不能帮上忙。它实际上可能是一个复制品。。。