using pcfitcylinder - unexpected results?

10 vues (au cours des 30 derniers jours)
Dan Howe
Dan Howe le 16 Avr 2020
Commenté : Tao Liu le 23 Oct 2023
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);

Réponses (2)

Prabhan Purwar
Prabhan Purwar le 21 Avr 2020
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 commentaire
Dan Howe
Dan Howe le 28 Avr 2020
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.

Connectez-vous pour commenter.


Dale Robinson
Dale Robinson le 15 Nov 2022
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 commentaire
Tao Liu
Tao Liu le 23 Oct 2023
Hi Dale,
I totally agree with you. I also got different results for each simulation. Do you have a reliable solution?
Thanks
Tao

Connectez-vous pour commenter.

Catégories

En savoir plus sur Statistics and Machine Learning Toolbox dans Help Center et File Exchange

Produits


Version

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by