簡體   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