fit curve with parameter

1 view (last 30 days)
Stefan Lang
Stefan Lang on 19 Oct 2020
Commented: J. Alex Lee on 19 Oct 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 Comments
Rik
Rik on 19 Oct 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')

Sign in to comment.

Accepted Answer

J. Alex Lee
J. Alex Lee on 19 Oct 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 Comments
J. Alex Lee
J. Alex Lee on 19 Oct 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

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!