从外部获取内部曲线

时间:2018-07-28 20:15:25

标签: matlab math

我有一条外部曲线,其最佳拟合多项式为n,用红色显示(见顶部),并带有以下参数。 x = 1,0.02,0.04,... 1.6 m

 Linear model Poly7:
 fitresult(x) = p1*x^7 + p2*x^6 + p3*x^5 + p4*x^4 + p5*x^3 + 
                p6*x^2 + p7*x + p8
 Coefficients (with 95% confidence bounds):
   p1 =      0.2904  (0.1959, 0.385)
   p2 =      -48.81  (-64.73, -32.89)
   p3 =        3515  (2367, 4664)
   p4 =  -1.406e+05  (-1.866e+05, -9.459e+04)
   p5 =   3.374e+06  (2.268e+06, 4.481e+06)
   p6 =  -4.858e+07  (-6.454e+07, -3.262e+07)
   p7 =   3.885e+08  (2.606e+08, 5.164e+08)
   p8 =  -1.331e+09  (-1.77e+09, -8.923e+08)

enter image description here

是否有任何功能可以以编程方式获得内部曲线(低8厘米,以黄色显示),而无需手动进行测量。我已经对其进行了手动测量,并获得了以下参数值。

fitresult(x) = p1*x^7 + p2*x^6 + p3*x^5 + p4*x^4 + p5*x^3 + 
                    p6*x^2 + p7*x + p8
     Coefficients (with 95% confidence bounds):
       p1 =      0.5445  (0.4419, 0.647)
       p2 =      -91.54  (-108.8, -74.29)
       p3 =        6595  (5351, 7840)
       p4 =   -2.64e+05  (-3.138e+05, -2.141e+05)
       p5 =   6.338e+06  (5.14e+06, 7.536e+06)
       p6 =   -9.13e+07  (-1.086e+08, -7.402e+07)
       p7 =   7.305e+08  (5.921e+08, 8.689e+08)
       p8 =  -2.505e+09  (-2.98e+09, -2.03e+09)

1 个答案:

答案 0 :(得分:4)

您可以使用polyder计算外部曲线的导数。它会给您每个点的曲线斜率。然后使用atan,您将获得相应的角度alpha。知道alpha即可轻松计算每个数据点的坐标偏移。

也许您需要避免一些特殊情况,但是我认为这种想法通常应该可行。

这里是一个例子:

% shift distance
d = -0.08; 

% original curve
x = 0:0.05:2; 
y = sin(x);

% fit for the original curve
p = polyfit(x,y,7)
fitresult = polyval(p,x);

% derivative coefficients of the fit
p_der = polyder(p);

% reconstructed derivative
fitresult_der = polyval(p_der,x);

% slope in each point
alpha = -atan(fitresult_der);

% shift in x and y according to the slope
dx = d*sin(alpha);
dy = d*cos(alpha);

% shifted curve
x_prime = x + dx;
y_prime = y + dy;

% fit for the shifted curve
p_prime = polyfit(x_prime,y_prime,7)

fitresult_prime = polyval(p_prime,x_prime);

%plots
figure;
plot(x, fitresult, 'o-');
hold on;
plot(x_prime, fitresult_prime, 'o-');

for i=1:numel(x)
    plot([x(i) x_prime(i)], [fitresult(i) fitresult_prime(i)], 'k-');
end

hold off;
grid on;
legend('original', 'shift');
axis equal;

原始曲线和平移曲线的参数:

p =

   -0.0001   -0.0004    0.0091   -0.0008   -0.1663   -0.0001    1.0000   -0.0000


p_prime =

   -0.0007    0.0071   -0.0160    0.0293   -0.1910    0.0372    0.9970   -0.1130

结果: enter image description here