fit curve with parameter
    6 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    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
  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')
Respuesta aceptada
  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
      
      
 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
      
 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
Más respuestas (0)
Ver también
Categorías
				Más información sobre Get Started with Curve Fitting Toolbox 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!


