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 CenterFile Exchange에서 Statistics 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