研究了一下,可以用下面的函数来实现voronoi图转到autoCAD.
- n=7;m=50;
- rand('state',n)
- x=rand(1,m);
- y=rand(1,m)
- [vx,vy]=voronoi(x,y)
- voronoi2acad('h2nder',x,y,vx,vy)
复制代码
scr的使用方法不在赘述了,感兴趣了查上篇帖子吧。生成结果如下(需要手动关掉捕捉和栅格,还有就是设置一下点样式)
最后,附上所需函数的源代码:
- function voronoi2acad(filename,x,y,vx,vy)
- % voronoi2acad(filename,x,y,vx,vy)
- % convert voronoi diagram generated by matlab into autoCAD.
- % filename - the scr file to be generated.
- %
- %
- % Exampe:
- % x=rand(1,30);
- % y=rand(1,30);
- % [vx,vy]=voronoi(x,y);
- % voronoi2acad('voronoiACAD',x,y,vx,vy)
- %
- % author Zhang Fujian.
- % email: zhangfujijan@gmail.com
- % May. 28, 2008
-
- fid=fopen([filename,'.scr'],'w');
- fprintf(fid,'line');
- for i=1:length(vx(1,:))
- fprintf(fid,'\n');
- fprintf(fid,'%g,%g\n',vx(1,i),vy(1,i));
- fprintf(fid,'%g,%g\n',vx(2,i),vy(2,i));
- fprintf(fid,'\n');
- end
- for i=1:length(x)
- fprintf(fid,'point\n');
- fprintf(fid,'%g,%g\n',x(i),y(i));
- end
- fclose(fid);
-
复制代码 |