Matlab產(chǎn)生IGES文件代碼【matlab源碼】
《Matlab產(chǎn)生IGES文件代碼【matlab源碼】》由會員分享,可在線閱讀,更多相關《Matlab產(chǎn)生IGES文件代碼【matlab源碼】(18頁珍藏版)》請在裝配圖網(wǎng)上搜索。
1、Matlab產(chǎn)生IGES文件代碼【matlab源碼】 畢業(yè)論文,設計, 題目學院學院專業(yè)學生姓名學號年級級指導教師 畢業(yè)教務處制表畢業(yè) Matlab產(chǎn)生IGES文件代碼 一、程序說明 本團隊長期從事matlab編程與仿真工作,擅長各類畢業(yè)設計、數(shù)據(jù)處理、圖 表繪制、 理論分析等,程序代做、數(shù)據(jù)分析 QQ38782670 具體信息聯(lián)系 二、程序示例 %產(chǎn)生數(shù)據(jù)并寫入iges文件 clc clear issearch=2;%0表示只寫點,1表示只寫線,2表示點線都寫 fprintf('正在寫文件。。。\n'); %產(chǎn)生正弦波文件 x=0:0.1:10; x=x
2、'; y=sin(x); Data=[xy]; Data(1,3)=0; write_iges('iges_sin.igs',Data,issearch) %產(chǎn)生peaks文件 [x,y,z]=peaks(30);xx=x(:); yy=y(:); zz=z(:); Data=[xxzzyy]; write_iges('iges_peaks.igs',Data,issearch) %產(chǎn)生拋物線文件 [x,y]=meshgrid(-1:0.1:1); z=x.A2+y.A2; xx=x(:); yy=y(:); zz=z(:); Data=[xxyyzz];
3、write_iges('iges_paowu.igs',Data,issearch) %產(chǎn)生解釋文件 xx=[10;0]; yy=[0;10]; zz=[0;0]; Data=[xxyyzz]; write_iges('igesforexplain.igs',Data,0)%產(chǎn)生Matlab圖標 [x,y]=meshgrid(linspace(-1,1,16));z=membrane; z=z(1:2:end,1:2:end,1:2:end);xx=x(:); yy=y(:); zz=z(:); Data=[xxzzyy]; write_iges('iges_matla
4、b.igs',Data,issearch) fprintf('寫文件結束。\n'); add_start_global函數(shù)文件: %構造開始段和全局段字符串 function[filename,file_str]=add_start_global(FileName) %開始段信息 start='Matlab-IGES-UG,Proe'; %全局段信息 timedata=clock; Time=sprintf('%4s%2s%2s.%2s%2s%2s',num2str(timedata(1)),num2str(timeda ta(2)),num2str(timedata(3)
5、),num2str(timedata(4)),num2str(timedata(5) ), num2str(floor(timedata(6)))); Author='USTCGJ_QSQ'; G_1='1H,'; G_2='1H;'; G_3='7HPRT0001'; G_4=strcat(num2str(length(FileName)),'H',FileName);%FileName G_5='49HPro/ENGINEERbyParametricTechnologyCorporation'; G_6='7H2007170'; G_7='32'; G_8='38';
6、 G_9='7'; G_10='38'; G_11='15'; G_12='7HPRT0001'; G_13='1.'; G_14='2'; G_15='2HMM'; G_16='32768'; G_17='0.5'; G_18=strcat(num2str(length(Time)),'H',Time);%Time; G_19='0.0865991'; G_20='866.025'; G_21=strcat(num2str(length(Author)),'H',Author);%Author; G_22='4HUSTC'; G_23='10'; G_24='
7、0'; G_25=strcat(num2str(length(Time)),'H',Time);%Time; %構造字符串 file_str=''; %start start=add_section_index(start,'S',1); file_str=strcat(file_str,start,'\n'); %global rowstr=''; count=0; fori=1:25 ifi==25 temp=strcat((['G_',num2str(i)]),';'); else temp=strcat((['G_',num2str(i)]),',');
8、end iflength(rowstr)+length(temp)>72 count=count+1; rowstr=add_section_index(rowstr,'G',count); file_str=strcat(file_str,rowstr,'\n'); rowstr=temp; else rowstr=strcat(rowstr,temp); ifi==25 count=count+1; rowstr=add_section_index(rowstr,'G',count); file_str=strcat(file_str,rowstr,'\n');
9、 end end end filename=FileName; end functionresult=add_section_index(str,section,index) result=sprintf('%-72s%s}',str,section,index);end write_iges函數(shù)文件: %寫igs文件 %FileName為寫入的文件名,Data為待寫入的數(shù)據(jù) functionwrite_iges(FileName,Data,PointOrLine)Index=0; %構造開始段和全局段字符串 [filename,file_str]=add_start
10、_global(FileName); %構造索引段和參數(shù)段 ifnargin==2 pointorline=2;%0表示只寫點,1表示只寫線,2表示點線都寫 else pointorline=PointOrLine; end ifpointorline==0 %寫點 [strDir2strPara2Index]= writePoint(Data(1:end,1),Data(1:end,2),Data(1:end,3),Index); file_str=strcat(file_str,strDir2); file_str=strcat(file_str,strPara2)
11、; elseifpointorline==1 %寫線 [strDir1strPara1Index]= writeLine(Data(1:end-1,1),Data(1:end-1,2),Data(1:end- 1,3),Data(2:end,1),Data(2:end,2),Data(2:end,3),Index); file_str=strcat(file_str,strDir1); file_str=strcat(file_str,strPara1); elseifpointorline==2 %寫線 [strDir1strPara1Index]= writeLine
12、(Data(1:end-1,1),Data(1:end-1,2),Data(1:end- 1,3),Data(2:end,1),Data(2:end,2),Data(2:end,3),Index); file_str=strcat(file_str,strDir1); %寫點 [strDir2strPara2Index]= writePoint(Data(1:end,1),Data(1:end,2),Data(1:end,3),Index); file_str=strcat(file_str,strDir2); file_str=strcat(file_str,strPara1)
13、; file_str=strcat(file_str,strPara2); end %構造結束段 str_end=sprintf('%s}%s}%s}%s}As}','S',1,'G',4,'D',2*Index,'P',Index,'T',1); file_str=strcat(file_str,str_end,'\n'); %寫入文件 fid=fopen(FileName,'wt'); fprintf(fid,file_str); fclose(fid); writeLine函數(shù)文件: %Index為總元素的個數(shù) function[strDir,strPara,In
14、dex]=writeLine(x1,y1,z1,x2,y2,z2, Index) if length(x1)~=length(y1)||length(x1)~=length(z1)||length(x2)~=length(y 2) ||length(x2)~=length(z2)||length(x2)~=length(y1) disp('2了,幾個線呀?’); end Direction=struct('type',[],...% 'paraPtr',[],...% 'version','1',... 'lineStyle','1',... 'layer','0',.
15、.. 'view','0',... 'matrix','0',... 'label','0',... 'status','00000001',... 'section','D',... 'type1',[],...% 'lineWeight','0',... 'color','2',... rowNum','1',... 'form','0',... 'reserved','',... 'reserved1','',... 'elementLabel',[],...% 'elementIndex',[],...% 'section1','D'... ); Li
16、ne=struct('pointDir',Direction,... 'x1',[],... 'y1',[],... 'z1',[],... 'x2',[],... 'y2',[],... 'z2',[],... 'ptr',[]... ); count=0; strDir=''; strPara=''; fori=1:length(x1) count=count+1; Index=Index+1; Line.pointDir.type='110'; Line.pointDir.elementLabel='LINE'; Line.pointDir.elemen
17、tIndex=num2str(count); Line.pointDir.paraPtr=num2str(Index); Line.pointDir.type1=Line.pointDir.type; Line.x1=x1; Line.y1=y1; Line.z1=z1; Line.x2=x2; Line.y2=y2; Line.z2=z2; Line.ptr=2*Index-1; %構造字符串 strDir_temp=sprintf('%8s%8s%8s%8s%8s%8s%8s%8s%8s%s}\n%8s%8s%8s%8s%8s %8 s%8s%8s%8s%s}',
18、... Line.pointDir.type,... Line.pointDir.paraPtr,... Line.pointDir.version,... Line.pointDir.lineStyle,... Line.pointDir.layer,... Line.pointDir.view,... Line.pointDir.matrix,... Line.pointDir.label,... Line.pointDir.status,... Line.pointDir.section,2*Index-1,... Line.pointDir.type1,...
19、Line.pointDir.lineWeight,... Line.pointDir.color,... Line.pointDir.rowNum,... Line.pointDir.form,... Line.pointDir.reserved,... Line.pointDir.reserved1,... Line.pointDir.elementLabel,... Line.pointDir.elementIndex,... Line.pointDir.section1,2*Index); strPara_temp=sprintf('%s,%.2f,%.2f,%.2f,
20、%.2f,%.2f,%.2f;',... Line.pointDir.type,... Line.x1(i),... Line.y1(i),... Line.z1(i),... Line.x2(i),... Line.y2(i),... Line.z2(i)); strPara_temp=sprintf('%-64s�P%7s',strPara_temp,2*Index- 1,Line.p ointDir.paraPtr); strDir=strcat(strDir,strDir_temp,'\n'); strPara=strcat(strPara,str
21、Para_temp,'\n');end writePoint函數(shù)文件: %Index為總元素的個數(shù) function[strDir,strPara,Index]=writePoint(x,y,z,Index) iflength(x)~=length(y)||length(x)~=length(z) disp('2了,幾個點呀?’); end Direction=struct('type',[],...% 'paraPtr',[],...% 'version','1',... 'lineStyle','1',... 'layer','0',... 'view','0',.
22、.. 'matrix','0',... 'label','0',... 'status','00000001',... 'section','D',... 'type1',[],...% 'lineWeight','0',... 'color','2',... 'rowNum','1',... 'form','0',... 'reserved','',... 'reserved1','',... 'elementLabel',[],...% 'elementIndex',[],...% 'section1','D'... ); Point=struct('poi
23、ntDir',Direction,... 'x',[],... 'y',[],... 'z',[],... 'ptr',[]... ); count=0; strDir=''; strPara=''; fori=1:length(x) count=count+1; Index=Index+1; Point.pointDir.type='116'; Point.pointDir.elementLabel='POINT'; Point.pointDir.elementIndex=num2str(count); Point.pointDir.paraPtr=num2st
24、r(Index); Point.pointDir.type1=Point.pointDir.type; Point.x=x; Point.y=y; Point.z=z; Point.ptr=2*Index-1; %構造字符串 strDir_temp=sprintf('%8s%8s%8s%8s%8s%8s%8s%8s%8s%s}\n%8s%8s%8s%8s%8s %8 s%8s%8s%8s%s}',... Point.pointDir.type,... Point.pointDir.paraPtr,... Point.pointDir.version,... Point
25、.pointDir.lineStyle,... Point.pointDir.layer,... Point.pointDir.view,... Point.pointDir.matrix,... Point.pointDir.label,... Point.pointDir.status,... Point.pointDir.section,2*Index-1,... Point.pointDir.type1,... Point.pointDir.lineWeight,... Point.pointDir.color,... Point.pointDir.rowNum,.
26、.. Point.pointDir.form,... Point.pointDir.reserved,... Point.pointDir.reserved1,... Point.pointDir.elementLabel,... Point.pointDir.elementIndex,... Point.pointDir.section1,2*Index); strPara_temp=sprintf('%s,%.2f,%.2f,%.2f;',... Point.pointDir.type,... Point.x(i),... Point.y(i),... Point.z
27、(i)); strPara_temp=sprintf('%-64s?P%7s',strPara_temp,2*Index- 1,Point.pointDi r.paraPtr); strDir=strcat(strDir,strDir_temp,'\n'); strPara=strcat(strPara,strPara_temp,'\n');end end writeColor函數(shù)文件: %Index為總元素的個數(shù) function[strDir,strPara,Index]=writeColor(r,g,b,Index) iflength(r)~=length(g)||l
28、ength(r)~=length(b) disp('2了,幾個點呀?’); end Direction=struct('type',[],...% 'paraPtr',[],...% 'version','1',... 'lineStyle','1',... 'layer','0',... 'view','0',... 'matrix','0',... 'label','0',... 'status','01000200',... 'section','D',... 'type1',[],...% 'lineWeight','0',... 'color','2',
29、... 'rowNum','1',... 'form','0',... 'reserved','',... 'reserved1','',... 'elementLabel',[],...%'elementIndex',[],...%'section1','D'... ); Color=struct('pointDir',Direction,... 'r',[],... 'g',[],... 'b',[],... 'ptr',[]... ); count=0; strDir=''; strPara=''; fori=1:length(r) count=coun
30、t+1; Index=Index+1; Color.pointDir.type='314'; Color.pointDir.elementLabel='COLOR'; Color.pointDir.elementIndex=num2str(count); Color.pointDir.paraPtr=num2str(Index); Color.pointDir.type1=Color.pointDir.type; Color.r=r; Color.g=g; Color.b=b; Color.ptr=2*Index-1; %構造字符串 strDir_temp=sprint
31、f('%8s%8s%8s%8s%8s%8s%8s%8s%8s%s}\n%8s%8s%8s%8s%8s %8 s%8s%8s%8s%s}',... Color.pointDir.type,... Color.pointDir.paraPtr,... Color.pointDir.version,... Color.pointDir.lineStyle,... Color.pointDir.layer,... Color.pointDir.view,... Color.pointDir.matrix,... Color.pointDir.label,... Color.poi
32、ntDir.status,... Color.pointDir.section,2*Index-1,... Color.pointDir.type1,... Color.pointDir.lineWeight,... Color.pointDir.color,... Color.pointDir.rowNum,... Color.pointDir.form,... Color.pointDir.reserved,... Color.pointDir.reserved1,... Color.pointDir.elementLabel,... Color.pointDir.el
33、ementIndex,... Color.pointDir.section1,2*Index); strPara_temp=sprintf('%s,%.1f,%.1f,%.1f;',... Color.pointDir.type,... Color.r(i),... Color.g(i),... Color.b(i)); strPara_temp=sprintf('%-64s�P%7s',strPara_temp,2*Index-1,Color. pointDir.paraPtr); strDir=strcat(strDir,strDir_temp,'\n'); strPara=strcat(strPara,strPara_temp,'\n'); end end
- 溫馨提示:
1: 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
2: 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
3.本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
5. 裝配圖網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。