如何在 MATLAB 中将圆柱体拟合到分散的 3D XYZ 点数据?

Pyy*_*Pyy 2 matlab surface point-clouds

我想知道是否有人可以为我提供一些在 MATLAB Curve Fitting Toolbox 中处理分散 XYZ 点数据的代码示例?我想将曲面拟合到近似圆柱体的点。

谢谢。

erf*_*fan 5

在 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
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

点云对象创建如下:

ptCloud = pointCloud(P);
Run Code Online (Sandbox Code Playgroud)

然后可以拟合模型:

maxDistance = 0.02;
model = pcfitcylinder(ptCloud, maxDistance);
hold on
plot(model)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

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