Converting an STL file to a 3D Surface/Equation
49 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
John D'Errico
am 26 Okt. 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 Kommentar
Siehe auch
Kategorien
Mehr zu Linear and Nonlinear Regression finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!