Fitting cone/cylinder of known dimensions to 3D surface data

37 次查看(过去 30 天)
I'm looking to fit a cone/cylinder of known dimensions to 3D surface data.
As a test, I created a cone using the parametric equations and downsample it to get some 3D surface data (see photo).
I need to fit to this data a cone whose dimensions are fixed but its orientation and origin are variable (so total 6 unknowns). These 6 parameters need to be determined (in the least square sense) based on the available data.
What would be the best approach to perform this?
I am using the following but so far have not had good luck with it.
  1. A function that uses fsolve to get the cone surface from an implicit form of the cone equation given the 6 parameters.
  2. lsqcurvefit that calls the above function and compares with the 3D data to optimize the 6 parameters.
Thanks!
  5 个评论
AP
AP 2021-6-11
Matt: I have not done anything specific to generate the initial guess. In this test case, I am providing a guess that is not too far from the original values. No, the 3D data points would not include the vertex (see example below). Its more like a part of the surface somewhere between the vertex and the base of the cone.
Yes, this is a right circular cone. I came across this answer (https://www.mathworks.com/matlabcentral/answers/109764-fitting-implicit-function-to-data) from you and I will see if that works for me.
Alex: Thanks for the link, I will check it out. I'm using fsolve because the cone surface (z) is related to the (x,y) coordinates through an implicit equation. Is there a better way?
J. Alex Lee
J. Alex Lee 2021-6-11
I don't think your response on the reasoning for using fsolve makes sense. When you say x, y, z coordinates are related implicitly, i think "minimize the function F(xData,yData,zData), where the surface of the cone is defined as 0=F(x,y,z)". Unless your data points were exactly on the surface, fsolve would fail. Alternatively, if your data points were exactly on the surface a bad/naive minimizer may fail.

请先登录,再进行评论。

采纳的回答

Matt J
Matt J 2021-6-12
编辑:Matt J 2021-6-13
I've recently added a cone-fitting routine to this FIle Exchange package,
I still consider it a beta-version for now, but it's performed well so far in a number of tests. Here is an example of usage,
vertex=[1,2,3].'; %ground truth vertex coordinates
cone_angle=20; %ground truth axis-to-surface angle
yaw=20; pitch=-45; %ground truth yaw/pitch orientation (degrees)
theta=[0:40:200];
h=linspace(5,10,31);
sig=0.01; %noise sigma
xyz = rightcircularconeFit.xyzsim(vertex,cone_angle,[yaw,pitch],...
theta,h,sig); %noisy surface samples
fobj=rightcircularconeFit(xyz), %perform the fit
%Visualize the fit
fobj.plot()
xlabel X; ylabel Y; zlabel Z;
axis vis3d
The results of the fit are,
fobj =
rightcircularconeFit with properties:
vertex: [1.0001 1.9994 2.9979]
cone_angle: 19.9902
height: 10.0113
yaw: 20.0104
pitch: -45.0145
  12 个评论
Matt J
Matt J 2021-6-15
编辑:Matt J 2021-6-15
I don't know of any prior sources, but if you find one, I'd be grateful to know about it.
AP
AP 2021-6-15
Sounds good!
Thank you very much for taking time to make the surface-fitting FEX package and for modifying it to cater to my problem.

请先登录,再进行评论。

更多回答(2 个)

Matt J
Matt J 2021-6-14
If you know where the given surface samples would be located on an unrotated/untranslated version of the cone/cylinder, then the rotation and translation can be calculated using absor (Download).

Matt J
Matt J 2021-6-11
编辑:Matt J 2021-6-11
I am providing a guess that is not too far from the original values.
If so, it sounds like there is an error in your calculation of the objective function and/or of the Jacobian, if you are providing it. One thing you should check is whether if you initialize the iterations with the exact original values, if lsqnonlin recognizes it as a solution, terminating in zero iterations with residuals=0.

类别

Help CenterFile Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by