MATLAB生成STL格式文件:3D打印应用

上一篇专栏,我提到了一个可以实现 三维显示的matlab工具包,并且得到了以下的结果。

但是我的思考并没有止于此。我在想能不能给它3D打印出来。于是,我询问了淘宝商家,明白3D打印一般支持的文件格式为stl、obj、fbx等。于是我索性尝试将gif转成stl。https://imagetostl.com/cn/convert/file/gif/to/obj

这个网站可以在线将gif转成obj,但是结果实在是不忍直视。哈哈,直接给我整了一个浮雕啊。于是在无意之间,我看到 这个up主的一篇专栏,大受启发。

gif直接转obj的结果

一开始我还是很兴奋的,毕竟可以导出stl文件,但是结果也不是很理想:还是平面的!!

于是,我又联想到那个三维显示的工具包,于是经过一番折腾终于给我搞出来了。贴上代码:

x=1:100;
[X,Y]=meshgrid(x,x);
Z=50*exp(-1/(2*15^2)*((X-50).^2+(Y-50).^2));

lond = 0.25:1:360.25;
latd = -89.5:1:89.5;
[X,Y] = meshgrid(lond,latd);
Z = [GRACE_GRACE_FO_ewh.csr,GRACE_GRACE_FO_ewh.csr(:,1)];
[xxgg,yygg,zzgg,xx,yy,zz] = out_3D(X,Y,Z);
figure

plot3(xxgg,yygg,zzgg)
hold on
plot3(xx,yy,zz)
axis equal
axis off
surf2stl('mytest.stl',xxgg,yygg,zzgg)


model='egm2008';  %nmax=2190
nmax=600;
% Computation of grid for the selected geopotential functional
[lond,latd,gh]=compute_geopot_grids(model,nmax,'functional','gh');
[xxgg,yygg,zzgg,xx,yy,zz] = out_3D(lond,latd,gh);
surf2stl('egm2008.stl',xxgg,yygg,zzgg)
surf2stl('egm2008_coast.stl',xx,yy,zz)


function [x,y,z,xx,yy,zz] = out_3D(lond,latd,elev,varargin)
exaggeration_factor=0.002;
radius=1;
units='m';
graph_label='';
coastlines=1;
coastlines_lw='';
countries=0;
countries_lw='';
gridd=0;
gridd_lw='';
gridd_lond=60;
gridd_latd=30;
rad=57.295779513082323;
theta=(90-latd)/rad;
phi=lond/rad;
% lond, latd may already be given as meshgrids
if ~(sum(size(phi)==size(theta))==2 && sum(size(phi)==size(elev))==2)
   [phi,theta]=meshgrid(phi,theta);
end
r=radius/exaggeration_factor+elev;
x=r.*sin(theta).*cos(phi);
y=r.*sin(theta).*sin(phi);
z=r.*cos(theta);
% coastline
%    load NaturalEarth_ne_50m_coastline
   cost = load('coastline-from-GMT-WNI-0-360.dat');
   ii=isnan(cost); %indices where NaN's are located
%    latd1=latd_NaturalEarth_ne_50m_coastline;
   latd1 = cost(:,2);
%    lond1=lond_NaturalEarth_ne_50m_coastline;
   lond1 = cost(:,1);
   latd1(ii)=0;
   lond1(ii)=0;

   gh_coast=interp2(lond,latd,elev,lond1,latd1);

   gh_coast(ii)=nan;
   latd1(ii)=nan;
   lond1(ii)=nan;

   theta=(90-latd1)/rad;
   phi=lond1/rad;

   r=radius/exaggeration_factor+gh_coast;
   xx=r.*sin(theta).*cos(phi);
   yy=r.*sin(theta).*sin(phi);
   zz=r.*cos(theta);
end

这个代码可以将EGM2008地球重力场转成STL文件,同时我将进行3D打印!!也就是下面的彩图gif显示的东东!

matlab转换的EGM2008地球重力场的3D模型(不是gif图片)

EGM2008地球重力场的gif动态图

QR Code
微信扫一扫,欢迎咨询~

联系我们
武汉格发信息技术有限公司
湖北省武汉市经开区科技园西路6号103孵化器
电话:155-2731-8020 座机:027-59821821
邮件:tanzw@gofarlic.com
Copyright © 2023 Gofarsoft Co.,Ltd. 保留所有权利
遇到许可问题?该如何解决!?
评估许可证实际采购量? 
不清楚软件许可证使用数据? 
收到软件厂商律师函!?  
想要少购买点许可证,节省费用? 
收到软件厂商侵权通告!?  
有正版license,但许可证不够用,需要新购? 
联系方式 155-2731-8020
预留信息,一起解决您的问题
* 姓名:
* 手机:

* 公司名称:

姓名不为空

手机不正确

公司不为空