Matlab产生IGES文件代码matlab源码.docx
- 文档编号:9434527
- 上传时间:2023-02-04
- 格式:DOCX
- 页数:17
- 大小:18.94KB
Matlab产生IGES文件代码matlab源码.docx
《Matlab产生IGES文件代码matlab源码.docx》由会员分享,可在线阅读,更多相关《Matlab产生IGES文件代码matlab源码.docx(17页珍藏版)》请在冰豆网上搜索。
Matlab产生IGES文件代码matlab源码
Matlab产生IGES文件代码【matlab源码】
毕业论文,设计,
题目学院学院专业学生姓名学号年级级指导教师
毕业教务处制表毕业
Matlab产生IGES文件代码
一、程序说明
本团队长期从事matlab编程与仿真工作,擅长各类毕业设计、数据处理、图表绘制、
理论分析等,程序代做、数据分析
具体信息联系
二、程序示例
%产生数据并写入iges文件
clc
clear
issearch=2;%0表示只写点,1表示只写线,2表示点线都写
fprintf('正在写文件。
。
。
\n');
%产生正弦波文件
x=0:
0.1:
10;
x=x';
y=sin(x);
Data=[xy];
Data(1,3)=0;
write_iges('iges_sin.igs',Data,issearch)
%产生peaks文件
[x,y,z]=peaks(30);xx=x(:
);
yy=y(:
);
zz=z(:
);
Data=[xxzzyy];
write_iges('iges_peaks.igs',Data,issearch)
%产生抛物线文件
[x,y]=meshgrid(-1:
0.1:
1);
z=x.^2+y.^2;
xx=x(:
);
yy=y(:
);
zz=z(:
);
Data=[xxyyzz];
write_iges('iges_paowu.igs',Data,issearch)
%产生解释文件
xx=[10;0];
yy=[0;10];
zz=[0;0];
Data=[xxyyzz];
write_iges('igesforexplain.igs',Data,0)%产生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_matlab.igs',Data,issearch)
fprintf('写文件结束。
\n');
add_start_global函数文件:
%构造开始段和全局段字符串
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)),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';
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='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)]),',');
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');
end
end
end
filename=FileName;
end
functionresult=add_section_index(str,section,index)
result=sprintf('%-72s%s}',str,section,index);end
write_iges函数文件:
%写igs文件
%FileName为写入的文件名,Data为待写入的数据
functionwrite_iges(FileName,Data,PointOrLine)Index=0;
%构造开始段和全局段字符串
[filename,file_str]=add_start_global(FileName);
%构造索引段和参数段
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);
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(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);
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);
end
writeLine函数文件:
%Index为总元素的个数
function[strDir,strPara,Index]=writeLine(x1,y1,z1,x2,y2,z2,
Index)
if
length(x1)~=length(y1)||length(x1)~=length(z1)||length(x2)~=length(y2)
||length(x2)~=length(z2)||length(x2)~=length(y1)
disp('2了,几个线呀~');
end
Direction=struct('type',[],...%
'paraPtr',[],...%
'version','1',...
'lineStyle','1',...
'layer','0',...
'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'...
);
Line=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.elementIndex=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}',...
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,...
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,%.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,strPara_temp,'\n');end
end
writePoint函数文件:
%Index为总元素的个数
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',...
'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('pointDir',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=num2str(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.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,...
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(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函数文件:
%Index为总元素的个数
function[strDir,strPara,Index]=writeColor(r,g,b,Index)
iflength(r)~=length(g)||length(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',...
'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=count+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=sprintf('%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.pointDir.status,...
Color.pointDir.section,2*Index-1,...
Color.pointDir.type1,...
Color.pointDir.lineWeight,...
Color.pointDir.color,...
Color.pointDir.rowNum,...
Color.pointDir.form,...
Color.pointDir.rese
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Matlab 产生 IGES 文件 代码 源码