【问题标题】:Matlab - Curve fitting for point cloud dataMatlab - 点云数据的曲线拟合
【发布时间】:2012-02-06 13:29:22
【问题描述】:

我有 10000 个 (x,y) 数据集,我需要为其拟合曲线。一旦我可以拟合曲线,我需要在曲线上以均匀的间隔获得点。然后我会继续修补..然后为我的最终目标进行 stl。现在我对曲线拟合感到震惊。请帮帮我。

描述链接:https://docs.google.com/open?id=0BxIgxUb0m51-ZDA2ZWU0NzItM2JkZS00MWI4LTg0ZTMtNTI0ZjQzMzIxMzU3

【问题讨论】:

  • 当 STL 是 C++ 特定时,是否有理由将其标记为 STL?
  • @templatetypedef:我认为它们的意思是 *.stl 文件类型 - 三角曲面的简单几何文件格式:en.wikipedia.org/wiki/STL_%28file_format%29

标签: matlab stl


【解决方案1】:

一种方法是最小二乘曲线拟合。

您需要拟合参数化曲线[x(t), y(t)],而不是简单曲线y(x)。根据您的链接,您似乎正在尝试拟合一条简单的曲线y(x)

MATLAB 文件交换here 提供了一个方便的最小二乘样条拟合工具SPLINEFIT

使用此工具,以下是一个简单示例,说明如何使用最小二乘样条拟合将平滑曲线拟合到一组噪声数据。在这种情况下,我生成了 10 个随机扰动的圆形数据集,然后以最小二乘的方式将 5 阶样条拟合到数据中。

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()

您的数据显然比这更复杂,但这可能会让您入门。

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-22
    • 1970-01-01
    • 2017-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多