using pcfitcylinder - unexpected results?

5 ビュー (過去 30 日間)
Dan Howe
Dan Howe 2020 年 4 月 16 日
コメント済み: Tao Liu 2023 年 10 月 23 日
Hi, I'm looking to use the pcfitcylinder function and to check how it works, was trying to construct a simple test case.
I've got the code below to generate some point cloud data to fit a cylinder to. I think the point cloud data is correct but the fitted cylinder is nowhere near close. Could anyone advise what the issue is (I'm sure it's what I'm passing into the function)?
Thanks
r=10; %radius
length=10;
ntheta=100; % number of points to sample around circumference
nz=4; %number of layers to slice along cylinder
A=rand(ntheta,nz); %generate random points
A=A*2*pi; %convert to angle
B=0; % eventually want to try B=rand(ntheta,nz);
X=(r+5*B).*cos(A); %X co-ordinate
Y=(r+5*B).*sin(A);
z=[0:length/(nz-1):length];
Z=repmat(z,ntheta,1);
mypointcloud=pointCloud([X(:),Y(:),Z(:)]);
maxDistance=1;
cyl=pcfitcylinder(mypointcloud,maxDistance)
scatter3(X(:),Y(:),Z(:));
hold on
pcshow(pcloud);
plot(cyl);

回答 (2 件)

Prabhan Purwar
Prabhan Purwar 2020 年 4 月 21 日
Hi,
Please refer to the following code:
r=1; %radius
length=1;
ntheta=100; % number of points to sample around circumference
nz=20; %number of layers to slice along cylinder
A=rand(ntheta,nz); %generate random points
A=A*2*pi; %convert to angle
B=0; % eventually want to try B=rand(ntheta,nz);
X=(r+5*B).*cos(A); %X co-ordinate
Y=(r+5*B).*sin(A);
z=[0:length/(nz-1):length];
Z=repmat(z,ntheta,1);
mypointcloud=pointCloud([X(:),Y(:),Z(:)]);
maxDistance=0.005;
cyl=pcfitcylinder(mypointcloud,maxDistance)
scatter3(X(:),Y(:),Z(:));
hold on
pcshow(mypointcloud);
plot(cyl);
Output:
Kindly refer to the following link:
Tip:
The following parameters plays a major role, as the algorithm to find a cylinder is based upon MSAC which relies upon the density of point clouds.
ntheta=100; % number of points to sample around circumference
nz=20; %number of layers to slice along cylinder
  1 件のコメント
Dan Howe
Dan Howe 2020 年 4 月 28 日
Thanks for the response but I only have a few 'slices' of point cloud data along the cylinder axis. I was surprised that the fitted cylinder could be so wildly out.
Given that my data slices are more or less planar I could just fit circles along each slice and best fit a line through circle centers. but pcfitcylinder seemed a more elegant approach if it gave a reasonable fit.

サインインしてコメントする。


Dale Robinson
Dale Robinson 2022 年 11 月 15 日
I too have found this pcfitcylinder to be very unreliable. If I repeat the exact same code, it gives different answers each time. The optimisation must be unstable. Going to write my own code instead
  1 件のコメント
Tao Liu
Tao Liu 2023 年 10 月 23 日
Hi Dale,
I totally agree with you. I also got different results for each simulation. Do you have a reliable solution?
Thanks
Tao

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeStatistics and Machine Learning Toolbox についてさらに検索

製品


リリース

R2016a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by