Is it possible to use splines and b-splines cooperatively?

57 Views Asked by At

Here is a sample of simplified latitude and longitude:

# Creating a snippet
tempData = {
    'lat' : [69.4, 69.35, 69.3, 68.1, 67.8, 67.1, 67, 67.15],
    'lon' : [-6.4, -3.6, -2.5, -1.7, -1.4, -0.4, -0.1, 0],
    'type' : ['A', 'A', 'B', 'A', 'A', 'A', 'B', 'A']
}

df = pd.DataFrame(tempData)

I am trying to find a plane path (parameters - not just sketch) between those points. The plane needs to go through the points of type A (cubic splines) but only fly-by points B (go in that direction but don't go through - same as control points in b-splines)

I am able to calculate splines for all points using code below:

pts = []
for i in range(0,df.shape[0]):
    x = df.iloc[i,1]
    y = df.iloc[i,0]
    pts.append((x,y))

pts = np.array(pts)

tck, u = si.splprep(pts.T, u=None, s=0.0, per=0) 
u_new = np.linspace(u.min(), u.max(), 1000)
x_new, y_new = si.splev(u_new, tck, der=0)

plt.plot(pts[:,0], pts[:,1], 'ro')
plt.plot(x_new, y_new, 'g--')
plt.show()

cubic splines

I'm also able to calculate b-splines for all points:

# calculate
x = df['lon'].values
y = df['lat'].values

t = range(df.shape[0])
ipl_t = np.linspace(0.0, df.shape[0] - 1, 100)

x_tup = si.splrep(t, x, k=3)
x_list = list(x_tup)
xl = x.tolist()
x_list[1] = xl + [0.0, 0.0, 0.0, 0.0]
x_i = si.splev(ipl_t, x_list)

y_tup = si.splrep(t, y, k=3)
y_list = list(y_tup)
yl = y.tolist()
y_list[1] = yl + [0.0, 0.0, 0.0, 0.0]
y_i = si.splev(ipl_t, y_list)

# plot
fig = plt.figure()

ax = fig.add_subplot()
plt.plot(x, y, 'or')
plt.plot(x_i, y_i, 'g')
plt.xlim([min(x) - 0.3, max(x) + 0.3])
plt.ylim([min(y) - 0.3, max(y) + 0.3])

b-splines

How can I merge those two methods to calculate B-splines at points B, cubic splines for points A, but still smooth curve between alltogether? The curve should look like second one but making sure I actually go through the points of type A. Also, is there a way to minimise polynomial wiggle even further (the wiggle for cubic splines between first two points is still way too much)

0

There are 0 best solutions below