基于组件的三维CAD系统开发的关键技术研究(二)
<p> 2 .2地形切剖面</p><p> 水电工程设计中经常遇到在地形图上切剖面的问题,借助Visual Lisp可以实现快速切剖面。</p>
<p> (1) 初始地形图处理</p>
<p> 把带z坐标的地形平面图进行变换,变换后z坐标值成为层名,为加快切剖面运行速度,把“LWPOLYLINE”和”SPLINE”均转化为”LINE“线,程序如下</p>
<p> (defun c:pltol()</p>
<p> ;LWPOLYLINE转化为LINE</p>
<p> (setq n 0)</p>
<p> (setq e (ssget"X" (list (cons 0 "LWPOLYLINE"))))</p>
<p> (setq sh (sslength e))</p>
<p> (if e</p>
<p> (while (< n sh)</p>
<p> (setq e1 (ssname e n))</p>
<p> (command "pedit" e1 "d" "")</p>
<p> (setq x (entget e1))</p>
<p> (setq ngc (atof (setq la (fld 8 x))))</p>
<p> (command "explode" e1)</p>
<p> (setq n (+ n 1))</p>
<p> ) ) )</p>
<p> (defun fld (num lst)</p>
<p> (cdr (assoc num lst))</p>
<p> )</p>
<p> (defun c:spltol ()</p>
<p> ;SPLINE转化为LINE</p>
<p> (setq n 0)</p>
<p> (setq e (ssget "X" (list (cons 0 "SPLINE"))))</p>
<p> (setq sh (sslength e))</p>
<p> (if e</p>
<p> (while (< n sh)</p>
<p> (setq x (entget (setq e1 (ssname e n))))</p>
<p> (setq nla (itoa (fix (caddr (fld 10 x)))))</p>
<p> (if (= (fld 0 x) "SPLINE")</p>
<p> (progn</p>
<p> (command "layer" "n" nla "c" </p>
<p> "6" nla "s" nla "")</p>
<p> (command"line")</p>
<p> (setq nm (length x)</p>
<p> dzs (fld 73 x) dzs1 (fld 74 x))</p>
<p> (while (> nm 5)</p>
<p> (if (= (car (nth nm x)) 10)</p>
<p> (progn</p>
<p> (setq b1 (nth nm x))</p>
<p> (setq x1 (cadr b1))</p>
<p> (setq y1 (caddr b1))</p>
<p> (setq z1 (cadddr b1))</p>
<p> (setq glb (list x1 y1))</p>
<p> (command glb)</p>
<p> ) )</p>
<p> (setq nm (- nm 1))</p>
<p> )))</p>
<p> (command "")</p>
<p> (setq n (+ n 1))</p>
<p> )))</p>
<p> (2)切剖面</p>
<p> 输入剖面编号,在平面地形图上指定两点确定剖面剖切线位置,指定剖面图起点,利用AutoCAD的inters函数搜索剖切线与地形图的全部交点,自动计算交点坐标,计算交点与剖面位置起点的距离,按各交点高程和与起点的距离形成剖面图各点坐标,即可用本文实例1坐标画线生成地形图的剖面。</p>
<p> (defun dxtent1 ()</p>
<p> (setq n 0 xdzb nil)</p>
<p> (setq xds 0)</p>
<p> (setq sh (sslength e1))</p>
<p> (while (< n sh)</p>
<p> (setq x (entget (ssname e1 n)))</p>
<p> (if (= (fld 0 x) "LINE")</p>
<p> (progn</p>
<p> (setq dxtgcgc (fld 8 x))</p>
<p> (setq dxtgcgc (atoi dxtgcgc))</p>
<p> (if (> dxtgcgc 10)</p>
<p> (progn</p>
<p> (setq pst (fld 10 x))</p>
<p> (setq pet (fld 11 x))</p>
<p> (setq zb (list gc</p>
<p> (list (car pst) (cadr pst))</p>
<p> (list (car pet) (cadr pet))</p>
<p> ))</p>
<p> (setq xdzb (cons zb xdzb))</p>
<p> (setq xds (+ xds 1))</p>
<p> ))))</p>
<p> (setq n (+ n 1))</p>
<p> ))</p>
<p> (defun c:dxtsec ()</p>
<p> (setq pmh (+ pmh 1))</p>
<p> (setq pmh (getstring "/n剖面号" ))</p>
<p> (setq pt1 (getpoint "/n剖切位置起点:"))</p>
<p> (setq pt2 (getpoint pt1 "/n剖切位置终点:"))</p>
<p> (setq pt3 (getpoint "/n剖面图布置:"))</p>
<p> (setq p01 pt3)</p>
<p> (setq e1 (ssget "F" (list pt1 pt2)));利用AutoCAD的目标选择“F”方式选取与剖切线相交的地形线。</p>
<p> (dxtent);获取与剖切线相交地形线的坐标</p>
<p> (setq mxgc -100)</p>
<p> (setq mngc 10000)</p>
<p> (setq m 0 pmp nil)</p>
<p> (setq n xds i 0)</p>
<p> (while (< i n)</p>
<p> (setq crosp</p>
<p> (inters pt1 pt2 (nth 1 (nth i xdzb)) (nth 2 (nth i xdzb)) 1)</p>
<p> );求剖切线与地形线的交点</p>
<p> (if (/= crosp nil)</p>
<p> (progn</p>
<p> (setq dxtgcgc (nth 0 (nth i xdzb)))</p>
<p> (setq mxgc (max mxgc dxtgcgc))</p>
<p> (setq mngc (min mngc dxtgcgc))</p>
<p> (setq dst (distance pt1 crosp));剖切线起点与交点的距离</p>
<p> (setq dst (* (/ blcz dxthtbl) dst))</p>
<p> (setq pmp (cons (list m dst dxtgcgc) pmp))</p>
<p> (setq m (+ m 1))</p>
<p> ))</p>
<p> (setq i (+ i 1))</p>
<p> ))</p>
页:
[1]