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

您所在的位置:网站首页 matlab怎么输出三维图形 MATLAB实现将xyz数据转成三维的stl文件

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

2024-01-28 01:55| 来源: 网络整理| 查看: 265

上一篇专栏,我提到了一个可以实现三维显示的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显示的东东!

 

 



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3