using pcfitcylinder - unexpected results?

7 visualizzazioni (ultimi 30 giorni)
Dan Howe
Dan Howe il 16 Apr 2020
Commentato: Tao Liu il 23 Ott 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);

Risposte (2)

Prabhan Purwar
Prabhan Purwar il 21 Apr 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 Commento
Dan Howe
Dan Howe il 28 Apr 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.

Accedi per commentare.


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

Accedi per commentare.

Categorie

Scopri di più su Statistics and Machine Learning Toolbox in Help Center e File Exchange

Prodotti


Release

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by