繁体   English   中英

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

[英]Python - get surrounding area of line (coordinates)

我把我的坐标保存在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

现在,“点”确实包含围绕coord.-line的多边形,它与coord.-line有所需的距离。 但是,多边形中仍可能存在一些交叉点。 我试图通过插值去掉它们(例如用scipy.interpolate.spline)。 但我无法管理它才能正常工作。

任何人都可以请帮助=)?

身材匀称确实有效:

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

谢谢你的暗示;)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM