fit curve with parameter

9 visualizaciones (últimos 30 días)
Stefan Lang
Stefan Lang el 19 de Oct. de 2020
Comentada: J. Alex Lee el 19 de Oct. de 2020
I have some points, annotated from an xray, along the spine. I need to fit a curve through these points. After that, i want to parametrize my fitted curve from 0 to 1, so i can move along the curve in equal intervals. If i just project my points onto the x axis, my line will be distorted.
So i want to choose point 0, which should give me the x/y coordinates of the fitted curve and the slope of the curve at this point. Point 0.5 should give me the point in the middle of the curve and its x/y values and the slope there, and point 1 the last point of the curve.
Any ideas how to do this? I thought about spline/cscvn, but i don't really get it...
  3 comentarios
Stefan Lang
Stefan Lang el 19 de Oct. de 2020
Which two curves? I'm just fitting one curve through some points (x,y). E.g. through 8 points, but then I want to have a function that can give me all the x and y values along the fitted curve. And this should be with a parameter t between 0 and 1, so when i set t = 0.5, i get the points (x,y) that are on the curve in the middle of the curve length.
Rik
Rik el 19 de Oct. de 2020
E.g. this:
a=linspace(0,pi,100);x=5*sin(a)+rand(size(a));y=6*cos(a)+rand(size(a));%replace with your data
subplot(1,2,1)
plot(x,y)
title('actual data')
subplot(1,2,2)
t=linspace(0,1,numel(x));
plot(t,x),hold on,plot(t,y),hold off
title('as a function of t')

Iniciar sesión para comentar.

Respuesta aceptada

J. Alex Lee
J. Alex Lee el 19 de Oct. de 2020
If i understand Rik correctly, I think you'd first have to estimate the t data by computing the cumulative arc length between your x and y data points. But for that to work, your annotated points need to be ordered (from your 0 to 1). If they are ordered, your cummulative arc length can be estimated by something like
function s = cummArcLength(x,y)
s = zeros(size(x));
for i = 2:length(x)
s(i) = s(i-1) + sqrt( ...
(x(i)-x(i-1))^2 ...
+ (y(i)-y(i-1))^2 ...
);
end
end
And then just divide s by s(end) to force it to [0,1].
  2 comentarios
Rik
Rik el 19 de Oct. de 2020
This would be more precise than what I was thinking of: if you have two arrays (x and y), you can use the index as your parameter (and divide by numel(x) instead of s(end)).
J. Alex Lee
J. Alex Lee el 19 de Oct. de 2020
[Approximate] arc length would be safer if points were very unevenly distributed.
And for completeness, in either case you'd want to do the interpolation one way or another on both x and y parametrically on t
tData = cummArcLength(xData,yData)
xFit = interp1(sData,xData,tFit) % or spline or whatever
yFit = interp1(sData,yData,tFit) % or spline or whatever
If you have a predetermined set of tFit you are interested in. Maybe using something like splines makes it easier to create a function that can be evaluated at arbitrary t

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Splines en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by