Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting internal curve from external

Tags:

math

matlab

I have a external curve with best fitted polynomial of degree n , shown in red (see top) with following parameters. 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

Is there any function to get internal curve ( 8 cm lower and shown in yellow) programmatically and without measuing it manually. I have measured it manually and got the following values of the parameters.

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)
like image 993
Shahgee Avatar asked Nov 22 '25 21:11

Shahgee


1 Answers

You can calculate the derivative for the external curve using polyder. It will give you the slope of the curve in each point. Then using atan you'll get the acccording angle alpha. Knowing alpha it's easy to calculate the coordinate shift for each data point.

Perhaps you need to avoid some special cases, but I think the idea should generally work.

Here is an example:

% 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;

Parameters for the original and shifted curves:

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

The result: enter image description here

like image 142
Anton Avatar answered Nov 25 '25 09:11

Anton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!