2016-09-20 146 views
0

我想知道是否有人可以为我提供一些代码示例,以便在MATLAB曲线拟合工具箱中处理分散的XYZ点数据?我想拟合一个曲面来逼近圆柱体。如何在MATLAB中将圆柱拟合成分散的3D XYZ点数据?

谢谢。

+0

没有经验,但是你看过Matlab [Surface fitting page](http://uk.mathworks.com/help/curvefit/surface-fitting.html)的链接吗? – Steve

回答

3

在Matlab R2015b及更高版本中,您可以使用pcfitcylinder将圆柱体适配到pointCloud对象。让我们产生的示例数据开始看到它是如何工作的:

[theta, r, h] = meshgrid(0:.1:6.28, 1, 0:.2:4); % making a cylinder 
r = r + 0.05 * randn(size(r)); % adding some radial noise 
[x, y, z] = pol2cart(theta, r, h); % transforming the coordinate system 
P = (rotx(60) * [x(:), y(:), z(:)]')'; % rotating the data points around x axis 
figure; 
scatter3(P(:, 1), P(:, 2), P(:, 3)) 
axis equal 

enter image description here

点云对象如下创建:

ptCloud = pointCloud(P); 

则该模型可装:

maxDistance = 0.02; 
model = pcfitcylinder(ptCloud, maxDistance); 
hold on 
plot(model) 

​​

根据您的数据,要获得合理的气缸,您可能需要查看pcfitcylinder并考虑包括其他输入参数。

+0

耶为花哨的情节 –