Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab - Curve fitting for point cloud data

Tags:

stl

matlab

I have 10000 data sets of (x,y) for which i need to fit a curve. Once I could fit a curve, i need to get points on the curve with an uniform interval. Then I would proceed to patch..and then to stl for my ultimate objective. Right now i'm struck with the curve fitting. Kindly help me out.

Link for the description: https://docs.google.com/open?id=0BxIgxUb0m51-ZDA2ZWU0NzItM2JkZS00MWI4LTg0ZTMtNTI0ZjQzMzIxMzU3

like image 765
user1191408 Avatar asked May 19 '26 06:05

user1191408


1 Answers

One approach would be least squares curve fitting.

You would need to fit a parameterised curve [x(t), y(t)], not a simple curve y(x). Based on your link it looks like you are trying to fit a simple curve y(x).

There's a handy least-squares spline fitting tool SPLINEFIT available from the MATLAB file exchange here.

Using this tool, the following is a simple example of how you can use least-squares spline fitting to fit a smooth curve to a set of noisy data. In this case I generated 10 randomly perturbed circle data sets and then fit a spline of order 5 to the data in a least squares fashion. enter image description here

function spline_test

%% generate a set of perturbed data sets for a circle
   xx = [];
   yy = [];
   tt = [];
   for iter = 1 : 10
   %% random discretisation of a circle
      nn = ceil(50 * rand(1))
   %% uniform discretisation in theta
      TT = linspace(0.0, 2.0 * pi, nn)';
   %% uniform discretisation
      rtemp = 1.0 + 0.1 * rand(1);
      xtemp = rtemp * cos(TT);
      ytemp = rtemp * sin(TT);
   %% parameterise [xtemp, ytemp] on the interval [0,2*pi]
      ttemp = TT;
   %% push onto global arrays
      xx = [xx; xtemp];
      yy = [yy; ytemp];
      tt = [tt; ttemp];    
   end

%% sample the fitted curve on the interval [0,2*pi]
   ts = linspace(0.0, 2.0 * pi, 100);

%% do the least-squares spline fit for [xx(tt), yy(tt)]
   sx = splinefit(tt, xx, 5, 'p');
   sy = splinefit(tt, yy, 5, 'p');

%% evaluate the fitted curve at ts
   xs = ppval(sx, ts);
   ys = ppval(sy, ts);

%% plot data set and curve fit
   figure; axis equal; grid on; hold on;
   plot(xx, yy, 'b.');
   plot(xs, ys, 'r-');

end      %% spline_test()

Your data is obviously more complicated than this, but this might get you started.

Hope this helps.

like image 55
Darren Engwirda Avatar answered May 20 '26 19:05

Darren Engwirda



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!