Matlab - 点云数据的曲线拟合
问题描述:
我有10000个数据集(x,y),我需要拟合曲线。一旦我能够拟合一条曲线,我需要以均匀的间隔得到曲线上的点。然后,我会继续修补......然后为了达到我的最终目标。现在我对曲线拟合感到震惊。请帮助我。Matlab - 点云数据的曲线拟合
链接的描述:https://docs.google.com/open?id=0BxIgxUb0m51-ZDA2ZWU0NzItM2JkZS00MWI4LTg0ZTMtNTI0ZjQzMzIxMzU3
答
一种方法是最小二乘曲线拟合。
您需要拟合参数化曲线[x(t), y(t)]
,而不是简单的曲线y(x)
。根据你的链接,它看起来像你试图适合一个简单的曲线y(x)
。
有一个方便的最小二乘样条拟合工具SPLINEFIT
可从MATLAB文件交换here可用。
使用此工具,下面是一个简单示例,说明如何使用最小二乘样条拟合将光滑曲线拟合到一组噪声数据。在这种情况下,我生成了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()
你的数据显然比这更复杂,但这可能会让你开始。
希望这会有所帮助。
当STL是C++特有的时候,是否有这个标签为STL的原因? – templatetypedef 2012-02-06 04:44:23
@templatetypedef:我假设他们是指'* .stl'文件类型 - 用于三角化表面的简单几何文件格式:http://en.wikipedia.org/wiki/STL_%28file_format%29 – 2012-02-06 04:52:44