How to fit a cylinder to scattered 3D XYZ point data in MATLAB?

北城以北 提交于 2019-12-11 00:28:13

问题


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? I would like to fit a surface to points that approximate a cylinder.

Thanks.


回答1:


In Matlab R2015b and above, You can use pcfitcylinder to fit a cylinder to a pointCloud object. 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.



来源:https://stackoverflow.com/questions/39589384/how-to-fit-a-cylinder-to-scattered-3d-xyz-point-data-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!