How to aproximate a set of points into a polynomial parametric spline

조회 수: 4 (최근 30일)
Arianna CECI
Arianna CECI 2020년 10월 31일
댓글: Moreno, M. 2022년 4월 16일
I have a set of points into an xlsx file and I would like to aproximate this set of points into a parametric curve,
Curve where and are in polynomial form, for example:
where and are the coefficients
This is the spline representation in excel, and i would like to do the same thing but using matlab and also try to aproximate the curve equation.
I know the basics of matlab, like using polyfit and polyval but does not work for this case, i tried doing an aproximation with Bezier Curve but uses the set of points as "control points" and doing so the curve does not pass through all the points.
If anyone has any advice for this problem it would be much apreciated :) Thanks

답변 (2개)

John D'Errico
John D'Errico 2020년 10월 31일
편집: John D'Errico 2020년 10월 31일
Download my interparc utility, which does exactly what you want, though it is not a polynomial tool, but a spline tool. Lacking your data, I can't go much further.
Can you find a parametric polynomial form? Possibly. Well, perhaps I should say I can. Do you need it? Why?

Moreno, M.
Moreno, M. 2022년 4월 16일
It is possible to fit a Bézier curve through your points, and then transform its control points to Bernstein basis. The following function bsplfit fits a Bezier curve bspl through a series of points:
And, the Bernstein coefficients (https://en.wikipedia.org/wiki/B%C3%A9zier_curve) are obtained as (factorial calculations can be modified if there are floating-point exception errors, for more than 170 points to fit. Note that overflows happen in the class double if there are more than 57 points to fit). This coefficients are the polynomial form of a Bézier curve. When the control points 'x' are parsed as input, the polynomial coefficients are:
function c = bez2ber(x)
n = size(x, 1) - 1;
N = prod(1 : n);
c = x;
for i = 1 : n - 1
I = prod(1 : i);
s = (-1) ^ i;
j = s * x(1, :) / I;
for k = 1 : i - 1
s = -s;
j = j + s * x(k + 1, :) / prod(1 : k) / prod(1 : i - k);
end
j = j + x(i + 1, :) / I;
c(i + 1, :) = N / prod(1 : n - i) * j;
end
s = (-1) ^ n;
j = s * x(1, :) / N;
for k = 1 : n
s = -s;
j = j + s * x(k + 1, :) / prod(1 : k) / prod(1 : n - k);
end
c(n + 1, :) = N * j;
end
Example:
% 50 points to fit with a curve of order 7
a = [0.117398673031460,0.953748444824301;0.117833137935425,0.927141442361390;0.121699059272131,0.895310554454398;0.128723944752550,0.859376538882510;0.138640166793072,0.820393660102137;0.151183200708567,0.779346475384486;0.166090110859401,0.737147055532541;0.183098284752403,0.694632640177448;0.201944415095776,0.652563727654311;0.222363729807971,0.611622599457391;0.244089469980494,0.572412279274718;0.266852615794680,0.535455926602106;0.290381860392405,0.501196664936579;0.314403831700756,0.469997844549202;0.338643562210649,0.442143739837317;0.362825206709393,0.417840681256196;0.386673007967213,0.397218621830092;0.409912510377714,0.380333138242702;0.432272021552304,0.367167866507035;0.453484321868560,0.357637372214691;0.473288621972548,0.351590455364546;0.491432768235094,0.348813889770841;0.507675696162002,0.349036597050686;0.521790131758226,0.351934255190964;0.533565540845991,0.357134341694647;0.542811326336862,0.364221611306520;0.549360273457764,0.372744008318308;0.553072242930961,0.382219013453214;0.553838112107967,0.392140425329867;0.551583964057427,0.401985576505671;0.546275524606938,0.411222984099566;0.537922847338815,0.419320434994198;0.526585246539823,0.425753505617490;0.512376478104846,0.430014516303629;0.495470168394511,0.431621920233452;0.476105491046761,0.430130126954249;0.454593091742385,0.425139760478963;0.431321260924483,0.416308351964806;0.406762354471901,0.403361466971279;0.381479462326599,0.386104267297600;0.356133325074980,0.364433507399538;0.331489498483164,0.338349965385659;0.308425765986219,0.307971308592975;0.287939799131329,0.273545393741999;0.271157065974929,0.235464001671216;0.259338987433779,0.194277006650956;0.253891341589990,0.150706980276670;0.256372915950002,0.105664229941621;0.268504407657516,0.0602622718889815;0.292177571660369,0.0158337388433344];
b = bsplfit(a, 7);
c = bez2ber(b);
d = zeros(100, 2);
t = (0 : 1 / (100 - 1) : 1)';
for i = 1 : 7
d = d + c(i, :) .* t .^ (i - 1);
end
plot(d(:, 1), d(:, 2))
hold on
plot(a(:, 1), a(:, 2), '.')
legend('Fitted Curve', 'Data Points')
  댓글 수: 1
Moreno, M.
Moreno, M. 2022년 4월 16일
https://uk.mathworks.com/matlabcentral/fileexchange/110220-polynomial-and-bezier-coefficient-conversion

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Splines에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by