MATLAB实现将xyz数据转成三维的stl文件

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

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

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

一开始我还是很兴奋的,毕竟可以导出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显示的东东!

 

 

  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我是水怪的哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值