[英]How to fit a cylinder to scattered 3D XYZ point data in MATLAB?
I was wondering if it was possible for someone to provide me with some code examples for working with scattered XYZ point data in MATLAB Curve Fitting Toolbox? 我想知道是否有人可以在MATLAB Curve Fitting Toolbox中为我提供一些代码示例来处理分散的XYZ点数据? I would like to fit a surface to points that approximate a cylinder. 我想将表面拟合到近似圆柱的点。
Thanks. 谢谢。
In Matlab R2015b and above, You can use pcfitcylinder
to fit a cylinder to a pointCloud
object. 在Matlab R2015b及更高版本中,您可以使用pcfitcylinder
将圆柱体拟合到pointCloud
对象。 Let's start with producing an example data to see how it works: 让我们从生成示例数据开始,看看它是如何工作的:
[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
The point cloud object is created as follows: 点云对象创建如下:
ptCloud = pointCloud(P);
Then the model can be fitted: 然后可以安装模型:
maxDistance = 0.02;
model = pcfitcylinder(ptCloud, maxDistance);
hold on
plot(model)
Depending on your data, to get a reasonable cylinder you might need to take a look at pcfitcylinder
and consider including other input arguments. 根据您的数据,要获得合理的柱面,您可能需要查看pcfitcylinder
并考虑包含其他输入参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.