Python - get neighborhood of a line (coordinates)
I have my coordinates stored in numpy x and y arrays. Now all I want is to get a polygon (respectively arrays of points) that defines the surrounding area with a given width parameter.
The problem is that I need to have a polygon without (!) Intersections. But this happens when there is a narrow curve. It would be better for my application to define these points and omit them. Is there a way to find these points easily?
So far I have:
# 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
The "points" now contain a polygon surrounding the coordinate line that has the desired distance to the coordinate. However, there may still be some intersections in the polygon. I tried to get rid of them by interpolation (with scipy.interpolate.spline for example). But I couldn't work normally.
Can anyone help =)?
source to share