Python -获得线(坐标)的周围区域



我有我的坐标保存在numpy数组x和y。现在我想要的是一个多边形(分别是点的数组),它用给定的宽度参数定义周围区域。

我的问题是,我需要有一个多边形没有(!)交集。但这确实会发生,当有一条狭窄的曲线时。对于我的应用程序,最好识别这些点并省略它们。有没有一种方法可以很容易地找到这些点?

到目前为止,我有:

# x contains x coords
# y contains y coords
# angle contains the current moving direction (radian)
import numpy as np
phi = np.pi/2 + angle
x_left = x + dist*np.cos( phi )
y_left = y + dist*np.sin( phi )
x_right = x - dist*np.cos( phi )
y_right = y - dist*np.sin( phi )
x_total = hstack((x_left, x_right[::-1]))
y_total = hstack((y_left, y_right[::-1]))        
##----- Omit Points with minimal dist < threshold to ANY point on traj
x_res = []
y_res = []
for idx in range(len(x_total)):
    m = np.min( np.sqrt( (x-x_total[idx])**2 + (y-y_total[idx])**2) )
    if m > dist-epsilon:
        x_res.append( x_total[idx] )
        y_res.append( y_total[idx] )    
points = np.vstack( (x_res, y_res) ).T

现在,"points"确实包含了围绕着坐标线的多边形,该多边形与坐标线有期望的距离。然而,在多边形中仍然会有一些交点。我试图通过插值(例如使用scipy.interpolate.spline)来摆脱它们。但是我不能使它正常工作。

谁能帮帮我=)?

shape did work:

import shapely.geometry as shgeo
line = vstack( (x,y) ).T
line = shgeo.LineString( line )
surrounding_polygon = line.buffer( 10,cap_style=3 ) # 10=Dist

最新更新