Converting an STL file to a 3D Surface/Equation
이전 댓글 표시
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개)
카테고리
도움말 센터 및 File 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!
