我正在从一堆(x,y)采样点拟合参数样条曲线(t)。如何计算与斜率和一个点给出的线的交点?在我的特殊情况下,样条与线相交一次或根本不相交,但不会多次。
这是样条和线的代码......
import matplotlib.pyplot as plt
import numpy as np
from scipy import interpolate
# Fit spline from points
x = np.array([152, 200, 255, 306, 356, 407, 457, 507, 561, 611, 661, 711, 761, 811, 861])
y = np.array([225, 227, 229, 229, 228, 226, 224, 222, 218, 215, 213, 212, 212, 215, 224])
tck, u = interpolate.splprep((x, y), k=3, s=1)
# Plot it...
u = np.linspace(0, 1, 100)
xy = np.asarray(interpolate.splev(u, tck, der=0))
plt.plot(*xy)
# Line defined by slope and (x, y) point
m = 3
(x, y) = (500, 100)
# Plot it...
x_vals = np.array([400, 700])
y_vals = m * (x_vals - x) + y
plt.plot(x_vals, y_vals)
plt.show()