Daniel
Daniel

Reputation: 576

Interpolating a smooth path for points ascending in the y-axis

The goal here is to generate a smooth path through the points.The path dose not strictly have to go though all the points but it has to be close to a linear interpolation on the points.

I have tried using cubic interpolation but in some cases, like the 'bad case' here, the interpolated path deviates to much from the original points. The images here show a good case and a bad case. The goal is to generate points for a path looking like the good case always. In these cases here 2100 points are interpolated for the path using Scipys interpolate scipy.interpolate.interp1d(y, x, kind='cubic', assume_sorted=True) The points are sorted to have ascending y-values. The interpolation is done on the y-axis. The points that are interpolated for the two cases are the following:

Good case
23.204308,-150.612090
14.039986,-149.129036
5.546616,-144.278745
-1.650596,-137.243629
-6.973690,-126.542852
-8.825059,-114.238668
-9.050130,-100.383011
-8.133504,-67.950063
-7.382615,-48.586878
-5.116275,-29.257957
4.157739,-14.768362
13.102034,-7.162435
22.090450,-3.862909 
    Bad case
    23.670263,-147.947479
    14.505940,-146.464425
    6.012571,-141.614133
    -1.184641,-134.579017
    -6.507735,-123.878240
    -8.359104,-111.574057
    -8.584175,-97.718399
    -7.667549,-65.285451
    -6.916660,-45.922266
    -4.650320,-26.593345
    4.623694,-12.103750
    13.567988,-4.497823
    22.598071,-3.951675

Good case and bad case

What other curve fitting or interpolation methods can be used to generate a smooth path of points for these cases?

Both Akima and pchip solved the problem as @ev-er suggested. Results from Akima and pchip is seem in the images attached.

Pchip vs Akima

Upvotes: 2

Views: 456

Answers (1)

ev-br
ev-br

Reputation: 26030

Looks like a case for pchip or Akima1DInterpolator from scipy.interpolate

Upvotes: 1

Related Questions