Fitting cone/cylinder of known dimensions to 3D surface data
9 views (last 30 days)
Show older comments
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.
- A function that uses fsolve to get the cone surface from an implicit form of the cone equation given the 6 parameters.
- lsqcurvefit that calls the above function and compares with the 3D data to optimize the 6 parameters.
Thanks!
5 Comments
J. Alex Lee
on 11 Jun 2021
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.
Accepted Answer
Matt J
on 12 Jun 2021
Edited: Matt J
on 13 Jun 2021
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 Comments
More Answers (2)
Matt J
on 14 Jun 2021
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).
0 Comments
Matt J
on 11 Jun 2021
Edited: Matt J
on 11 Jun 2021
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.
0 Comments
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

