scipy: Trajektorie interpolieren

Ich habe eine Flugbahn, die aus einer Folge von(x, y) Paare. Ich möchte Punkte auf dieser Trajektorie mit Splines interpolieren.

Wie mache ich das? Verwendenscipy.interpolate.UnivariateSpline funktioniert da auch nichtx Nochy sind monoton. Ich könnte eine Parametrisierung einführen (z. B. Länged entlang der Flugbahn), aber dann habe ich zwei abhängige Variablenx (d) undy (d).

Beispiel:

import numpy as np
import matplotlib.pyplot as plt
import math

error = 0.1
x0 = 1
y0 = 1
r0 = 0.5

alpha = np.linspace(0, 2*math.pi, 40, endpoint=False)
r = r0 + error * np.random.random(len(alpha))
x = x0 + r * np.cos(alpha)
y = x0 + r * np.sin(alpha)
plt.scatter(x, y, color='blue', label='given')

# For this special case, the following code produces the
# desired results. However, I need something that depends
# only on x and y:
from scipy.interpolate import interp1d
alpha_i = np.linspace(alpha[0], alpha[-1], 100)
r_i = interp1d(alpha, r, kind=3)(alpha_i)
x_i = x0 + r_i * np.cos(alpha_i)
y_i = x0 + r_i * np.sin(alpha_i)
plt.plot(x_i, y_i, color='green', label='desired')

plt.legend()
plt.show()

Antworten auf die Frage(1)

Ihre Antwort auf die Frage