How can I create a 3D solid body from a surface plot (x y z data points) and export it (preferably as STL) to a CAD software?

조회 수: 19 (최근 30일)
I have an x y z dataset and I want to create a solid 3D body (almost as if 'extruding' the surface down in a CAD software) from the topmost 3D surface. I am trying to achieve something similar to this
.
Having tried that, I am getting the following error :
Error using stlwrite (line 25)
Input argument must be a triangulation object.
Error in surface_to_3D (line 22)
stlwrite('test3D.stl',test3D);
If anyone could help me solve this, or tell me an alternative way to achieve this, that would be very helpful. All required files that I have used are attached.
P.S. The reason I cannot do it in a CAD software is because Solidworks or any other software cannot really read/detect the surface for extrusion, even if I use surf2stl to export it as an STL file.

답변 (2개)

Walter Roberson
Walter Roberson 2022년 7월 26일
There are file exchange contributions for surf2stl() and patch2stil()
  댓글 수: 3
SNIreaPER
SNIreaPER 2022년 7월 26일
My bad - I edited the subject and question; thanks for bringing it to my attention.

댓글을 달려면 로그인하십시오.


DGM
DGM 2025년 6월 30일
Well, nobody caught this one. OP was likely working off of examples that used stlwrite() from FEX #20922, but since R2018b, MATLAB has a built-in STL tool stlwrite(). Their usage isn't identical, so either change your usage to suit the tool you're using, or go get the tool you're trying to use.
% Generate x y z data
H = 0.8; % hurst exp
sigma = 100; % rms roughness
Lx = 1000; % length
m = 50; % number of pixels - x
n = 50; % number of pixels - y
z = artificial_surf(sigma, H, Lx, m , n);
x = linspace(0,Lx,m);
y = linspace(0,Lx*n/m,n);
[X,Y] = meshgrid(x,y);
surf(X,Y,z,'edgecolor','none'); %% plot surface
% Convert surface to solid
test3D = surf2solid(X,Y,z,'elevation',min(z(:))-500);
% write the file using FEX #20922
%stlWrite('test3D.stl',test3D) % i renamed this to avoid collision
% or write the file using the built-in writer
T = triangulation(test3D.faces,test3D.vertices);
stlwrite(T,'test3D.stl')
% read it back for show and tell
Tr = stlread('test3D.stl');
patch('faces',Tr.ConnectivityList,'vertices',Tr.Points,'facecolor','w','edgecolor','none');
view(3); view(144,44); camlight;
axis equal; grid on
xlabel('X'); ylabel('Y'); zlabel('Z')

카테고리

Help CenterFile Exchange에서 STL (STereoLithography)에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by