1

I have made a simple program that generates a path avoiding objects (objects here are shown in green and yellow). The path is shown in red.

This is meant to be used to navigate a small car however it cant make straight 45° turns and i need a way to make the path more smooth.

The yellow area is just a safety zone so there is no problem if it slightly cuts into it.

The plot is being made using the follow code (it updates as the object moves around).

path_data, = plt.plot(path_x, path_y, 'r-')

Image of path and object:

enter image description here

Regards, Jakob

Edit: The difference (from what i can tell) between my problem and the problem answered in the other thread is that I will not know what degree my curve will have beforehand and it will be used continuously so i can not plot it and the decide the degree myself. (I´m not an experienced programmer so I could very well be wrong)

JakobVinkas
  • 1,003
  • 7
  • 23
  • In theory, a circle is a polygon of infinite edges, so you can draw a curve with infinite tangents. If you enlarge your list of points to plot, you could smooth up the line; or you can plot quadratic functions instead of diagonal lines. Sounds more like a geometry issue than a Python issue. – Javier Apr 09 '19 at 13:56
  • @Javier My current plan is to make the car aim for a pint further away for it and by that doing that the car starts turning just before the path turns and then slowly approaching the line again as the car moves along. Is this similar to what you suggested or am I misstaken? – JakobVinkas Apr 09 '19 at 14:09
  • If you decide to plot like `plt.plot(path_x, path_y, 'r-')` is because you have defined points like (`path_x[0]`, `path_y[0]`)... So it's up to you where to aim the car, and what I suggest is to aim it e.g. from (12,0) to (16,4) first -sort of interpolation- and then to (20,8) to reduce the angle of turn in each vertex. Do that several times until you consider the line is acceptably 'curved'. – Javier Apr 09 '19 at 16:21

1 Answers1

0

You could try generating smoother data before plotting it. Usually one does this by fitting a smooth function to the data. Here you should invert x-axis and y-axis to get a real function (only for the interpolation process). One function you could use:

from scipy.interpolate import interp1d

The doc: https://docs.scipy.org/doc/scipy/reference/tutorial/interpolate.html

Orysza
  • 574
  • 1
  • 5
  • 10