Converting an STL file to a 3D Surface/Equation
47 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Given an arbitrary 3D CAD model (in STL, STEP format), is it possible to convert the model into a function , where x and y are points on the 3D model/surface? In other words, how do we fit an equation on an arbitrary 3D CAD model/surface?
I convert the STL file into a point cloud using CloudCompare software and then export the pointcloud to a .txt. From the txt file, I obtain the coordinates, and finally, I obtain surface fit using the cftool (curve fitting toolbox of MATLAB). The result is nowhere same as the original STL file. I have tried using all available interpolation options such as:
- Nearest neighbor
- Linear
- Cubic spline
- Biharmonic
- Thin-plate spline
The curve fitting code is enclosed herewith:
function fitresult = createFit(Xvec, Yvec, Zvec)
%CREATEFIT(XVEC,YVEC,ZVEC)
% Create a fit.
%
% Data for 'curve1' fit:
% X Input: Xvec
% Y Input: Yvec
% Z Output: Zvec
% Output:
% fitresult : a fit object representing the fit.
% gof : structure with goodness-of fit info.
%
% See also FIT, CFIT, SFIT.
% Auto-generated by MATLAB on 02-Aug-2024 11:41:46
%% Fit: 'curve1'.
[xData, yData, zData] = prepareSurfaceData( Xvec, Yvec, Zvec );
% Set up fittype and options.
%ft = 'nearestinterp';
%opts = fitoptions( 'Method', 'NearestInterpolant' );
%opts.ExtrapolationMethod = 'nearest';
ft = 'linearinterp';
opts = fitoptions( 'Method', 'LinearInterpolant' );
opts.ExtrapolationMethod = 'none';
%ft = 'thinplateinterp';
%opts = fitoptions( 'Method', 'ThinPlateInterpolant' );
%opts.ExtrapolationMethod = 'thinplate';
%opts.Normalize = 'on';
% Fit model to data.
[fitresult, ~] = fit( [xData, yData], zData, ft, opts );
% Plot fit with data.
%figure( 'Name', 'curve1' );
%h = plot( fitresult, [xData, yData], zData );
%legend( h, 'curve1', 'Zvec vs. Xvec, Yvec', 'Location', 'NorthEast', 'Interpreter', 'none' );
% Label axes
%xlabel( 'Xvec', 'Interpreter', 'none' );
%ylabel( 'Yvec', 'Interpreter', 'none' );
%zlabel( 'Zvec', 'Interpreter', 'none' );
Please also find enclosed the cartesian point cloud and stl file in the following links:
0 commentaires
Réponses (1)
John D'Errico
le 26 Oct 2024
Um, I think you misunderstand a few things.
It seems the STL model actually has thickness. So you have exported the entire thing, as a set of points, both to and bottom. We see that in the point cloud as what looks like almost noise. I'm not sure how to otherwise explain what is clearly a fuzzy cloud of points in the point cloud you plotted. Or, maybe the point cloud tool you used just generated some random set of points. We are not told. And that means the curve, at best, wants to pass through the middle of that cloud.
And of course, we don't see your data, or what you passed in. So we cannot even inpect it carefully to learn anything.
Next, can you just create an "equation" for any general point cloud? Well, no. Not such a trivial thing to do. Especially since your data has regions where that fitted model will have sharp derivative discontinuities, creases in the surface. And that means using something like a thin plate spline is going to generate complete crap. Such a curve tries to be smooth everythere.
At the other end of the fitting spectrum is a nearest neighbor interpolant. Now you have something that just grabs the nearest point from the point cloud, so effectively no interpolation at all.
The other methods will also have problems. I'm not sure why you are trying to do this, but you are not going to succeed.
1 commentaire
Voir également
Catégories
En savoir plus sur Linear and Nonlinear Regression dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!