- 积分
- 4906
- 明经币
- 个
- 注册时间
- 2004-6-16
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 作者 于 2010-8-31 21:36:52 编辑
宽LWPOLYLINE转线框,相当于剪影功能
采用纯VLISP方式实现将宽度>0的LWPOLYLINE转线框,对圆弧段采用3段圆弧模拟。
file:///D://PPL.bmp
源码如下:
主框架源码 - ;;;------------------------------------------------------------------------;;;
- ;;;宽POLYLINE转线框程序
- (defun c:PPL (/ ssen)
- (setq ssen (wjm_ss2lst (ssget (list (cons 0 "LWPOLYLINE")))))
- (foreach a ssen
- (ss-WPL->PL a T)
- (entdel a)
- )
- (princ "\n高山流水宽PL线转线框程序,命令PPL")
- (princ)
- )
- ;;;------------------------------------------------------------------------;;;
- (defun c:PPL1 (/ ssen)
- (setq ssen (wjm_ss2lst (ssget (list (cons 0 "LWPOLYLINE")))))
- (foreach a ssen
- (ss-WPL->PL a NIL)
- (entdel a)
- )
- (princ "\n高山流水宽PL线转单段线框程序,命令PPL1")
- (princ)
- )
- ;;; ---------------------------------------------------------------------------;;;
- ;;; SS-WPL->PL ;;;
- ;;; ---------------------------------------------------------------------------;;;
- ;;; function : Translate Wide LwPolyLine into Frame Border ;;;
- ;;; Arg : ;;;
- ;;; pl - PL Ename ;;;
- ;;; bool - boolean, T or NIL ;;;
- ;;; If you provide T , Then it'll translate PL to a Closed PL-Frame, ;;;
- ;;; If it's NIL , Single-stage PL-Frame. ;;;
- ;;; GE Alg : ;;;
- ;;; Trisect ARC length and width, Combine sidelines with Convexity ;;;
- ;;; ---------------------------------------------------------------------------;;;
- ;;; Example: ;;;
- ;;; (SS-WPL->PL PL_Ename T) ;_Return a Closed PL-Frame ;;;
- ;;; ---------------------------------------------------------------------------;;;
- ;;; Writen By GSLS(SS) 2010-08-08 ;;;
- ;;; (C) EasyCity OptDesign Studio of Building Structures ;;;
- ;;; Email: chlh_jd@126.com Tel:0592-5391029 Fax:0592-5391020 ;;;
- ;;; ---------------------------------------------------------------------------;;;
- (defun SS-WPL->PL (pl bool)
- (if bool
- ;;;整条返回封闭POLYLINE
- (mapcar 'entmake (ss-PL->Bound pl))
- ;;;逐段返回封闭POLYLINE
- (ss-pl->sbound pl)
- )
- )
主函数源码1:主函数源码2:-
- (defun SS-PL->SBound (pl / ent is_close pl_vetex
- b i lst1 lst2 w02 c0 p1
- p2 w11 w12 c1 b mid mid1
- mid2
- ) ;(setq pl (car (entsel)))
- (setq ent (entget pl '("*")))
- (setq is_close (rem (cdr (assoc 70 ent)) 2))
- (setq pl_vetex nil
- b nil
- )
- (foreach n ent ;_(setq e (assoc 10 ent))
- (if (or (= 10 (car n))
- (= 40 (car n))
- (= 41 (car n))
- (= 42 (car n))
- ) ;_ 结束or
- (progn
- (setq b (cons (cdr n) b))
- (if (= 4 (length b))
- (setq pl_vetex (append pl_vetex (list (reverse b)))
- b nil
- )
- )
- )
- )
- )
- (setq i 0
- b nil
- )
- (foreach a pl_vetex ;(setq a (nth 1 pl_vetex))
- (setq p1 (car a)
- w11 (cadr a)
- w12 (caddr a)
- c1 (cadddr a)
- b (nth (1+ i) pl_vetex)
- )
- ;_(if (= i 1) (princ "pause"))
- (if (and (null b) (= is_close 1))
- (setq b (car pl_vetex))
- )
- (if (setq p2 (car b))
- (progn
- (setq mid (ss-plwk-pts p1 w11 w12 c1 p2)
- lst1 nil
- lst2 nil
- lst3 nil
- lst4 nil
- )
- (repeat (/ (length mid) 2)
- (setq
- mid1 (car mid)
- mid2 (cadr mid)
- mid (cddr mid)
- lst1 (if (equal (car mid1) (car lst1))
- (cons (cadr mid1) lst1)
- (cons (cadr mid1) (cons (car mid1) lst1))
- )
- lst2 (if (equal (car mid2) (car lst2))
- (cons (cadr mid2) lst2)
- (cons (cadr mid2) (cons (car mid2) lst2))
- )
- lst3 (cons (caddr mid1) lst3)
- lst4 (cons (* -1.0 (caddr mid2)) lst4)
- )
- )
- (draw-pline
- (append (reverse lst1) lst2)
- 0.0
- (append (reverse lst3) (append (cons 0.0 lst4) (list 0.0)))
- nil
- -1
- 1
- )
- ) ;_end if pro
- )
- (setq i (1+ i))
- ) ;_end foreach
- ;_end if
- (princ)
- )
配套函数源码3:-
- ;;;配套函数-------------------------------------------------------------;;;
- (setq _pi2 1.5707963267948966192313216916395
- _2pi 6.283185307179586476925286766559
- _1d 0.0174532925199433
- )
- ;;;---------------------------------------------------------------------;;;
- ;;;获取单段PL线的4个角点和两边凸度
- ;;;直线段返回4个点((pt11 pt21 n11) (pt12 pt22 n12))
- ;;;高山流水2010-06-25
- ;;;(ss-plwk-pts p1 w11 w12 c1 p2)
- ;;;(setq pt1 p1 w1 w11 w2 12 n c1 pt2 p2)
- (defun ss-plwk-pts (pt1 w1 w2 n pt2 / ptcR0
- ptc0 R0 mpt0 ang1 ang2 ang2a ang2a/6 dw pt11
- pt12 pt21 pt22 ptm1 ptm2 ptcr1 ptcr2
- ptlst lst i n1 n2
- )
- (if (/= n 0.0)
- (progn
- (setq ptcR0 (SS-PTC-ptcR pt1 pt2 n)
- ptc0 (car ptcr0)
- R0 (cadr ptcr0)
- ang1 (angle ptc0 pt1)
- ang2 (angle ptc0 pt2)
- ang2a (angle (list 0.0 0.0 0.0) (gsls-XY->AB pt2 ptc0 ang1))
- ang2a (if (> n 0)
- ang2a
- (- ang2a _2pi)
- )
- ang2a/6 (/ ang2a 6.0)
- dw (/ (- w2 w1) 6.0)
- )
- (setq i 0
- ptlst nil)
- (repeat 7
- (setq pt11 (polar (polar ptc0 (+ ang1 (* i ang2a/6)) R0) (+ ang1 (* i ang2a/6) pi) (/ (+ w1 (* i dw)) 2.0))
- pt12 (polar (polar ptc0 (+ ang1 (* i ang2a/6)) R0) (+ ang1 (* i ang2a/6)) (/ (+ w1 (* i dw)) 2.0))
- ptlst (cons pt12 (cons pt11 ptlst))
- i (1+ i)
- )
- )
- ;(check-pt ptlst)
- (setq i 0
- ptlst (reverse ptlst)
- lst nil
- )
- (repeat 3
- (setq pt11 (nth (* i 4) ptlst)
- pt12 (nth (1+ (* i 4)) ptlst)
- ptm1 (nth (+ (* i 4) 2) ptlst)
- ptm2 (nth (+ (* i 4) 3) ptlst)
- pt21 (nth (+ (* i 4) 4) ptlst)
- pt22 (nth (+ (* i 4) 5) ptlst)
- ptcr1 (SS-PT-ptcR pt11 ptm1 pt21)
- ptcr2 (ss-pt-ptcr pt12 ptm2 pt22)
- n1 (ss-ptc-c pt11 pt21 (car ptcr1) (> n 0))
- n2 (ss-ptc-c pt12 pt22 (car ptcr2) (> n 0))
- )
- (if (> n 0.0)
- (setq lst (cons (list pt12 pt22 n2) (cons (list pt11 pt21 n1) lst)))
- (setq lst (cons (list pt11 pt21 n1) (cons (list pt12 pt22 n2) lst)))
- )
- (setq i (1+ i))
- )
- (setq lst (reverse lst))
- )
- (progn
- (setq ang (angle pt1 pt2)
- pt11 (polar pt1 (+ ang _pi2) (/ w1 2.0))
- pt12 (polar pt1 (- ang _pi2) (/ w1 2.0))
- pt21 (polar pt2 (+ ang _pi2) (/ w2 2.0))
- pt22 (polar pt2 (- ang _pi2) (/ w2 2.0))
- )
- (list (list pt11 pt21 0.0) (list pt12 pt22 0.0))
- )
- )
- )
- ;;;---------------------------------------------------------------------;;;
- ;;;已知圆弧起点、终点和凸度,求圆心和半径
- ;;;高山流水2010-06-25
- ;;;(SS-PTC-ptcR '(764814.0 -1.11779e+006 0.0) '(734523.0 -1.11239e+006) -0.722053)
- (defun SS-PTC-ptcR (pt1 pt2 convexity / ang mpt a b ptc R)
- (setq ang (angle pt1 pt2)
- mpt (midpt pt1 pt2)
- b (distance pt1 mpt)
- a (* b
- (/ (sin (- _pi2 (* 2.0 (atan convexity))))
- (cos (- _pi2 (* 2.0 (atan convexity))))
- )
- )
- ptc (polar mpt (+ ang _pi2) a)
- R (sqrt (+ (* a a) (* b b)))
- )
- (list ptc R)
- )
- ;;;---------------------------------------------------------------------;;;
- ;;;已知圆弧上的3点,求圆心和半径
- ;;;高山流水2010-06-25
- (defun SS-PT-ptcR (pt1 mpt pt2 / mpt1 mpt2 mpt11 mpt22 ptc R)
- (setq mpt1 (midpt pt1 mpt)
- mpt2 (midpt mpt pt2)
- mpt11 (polar mpt1 (+ (angle pt1 mpt) _pi2) 1000.0)
- mpt22 (polar mpt2 (+ (angle mpt pt2) _pi2) 1000.0)
- ptc (inters mpt1 mpt11 mpt2 mpt22 nil)
- R (distance ptc pt1)
- );_(check-pt (list pt1 mpt pt2))
- (list ptc R)
- )
- ;;;---------------------------------------------------------------------;;;
- ;;;已知圆弧的端点pt1->pt2,圆心ptc,求凸度
- ;;;高山流水2010-06-26
- ;;;
- (defun ss-ptc-c (pt1 pt2 ptc is_nsz / ang1 pt2a ang2)
- (setq ang1 (angle ptc pt1)
- pt2a (gsls-XY->AB pt2 ptc ang1)
- ang2 (angle (list 0.0 0.0 0.0) pt2a)
- )
- (if is_nsz
- nil
- (setq ang2 (- ang2 _2pi))
- )
- (/ (sin (/ ang2 4.0)) (cos (/ ang2 4.0)))
- )
- ;;;---------------------------------------------------------------------;;;
- ;;;将点XY坐标换算为AB坐标,AB坐标的原点为PT0,转角为R0
- ;;;A=(X-X0)cosR0+(Y-Y0)sinR0
- ;;;B=(Y-Y0)cosR0-(X-X0)sinR0
- (defun gsls-XY->AB (pt pt0 ANG / A B)
- (setq A (+ (* (- (car pt) (car pt0)) (cos ANG))
- (* (- (cadr pt) (cadr pt0)) (sin ANG))
- )
- B (- (* (- (cadr pt) (cadr pt0)) (cos ANG))
- (* (- (car pt) (car pt0)) (sin ANG))
- )
- )
- (list A B 0.0)
- )
- ;;;---------------------------------------------------------------------;;;
- ;;;求两点中点
- (defun midpt (pta ptb)
- (mapcar (function (lambda (x y)
- (/ (+ x y) 2.0)
- )
- )
- pta
- ptb
- )
- )
- ;;;---------------------------------------------------------------------;;;
- ;;;求直线、圆弧交点集,点凸版
- ;;;(ss-pl-inters '((713708.0 -563492.0) (717691.0 -570078.0) 0.0) '((715257.0 -566053.0) (720145.0 -553354.0) 0.280634))
- (defun ss-pl-inters (mid1 mid2 / intersections)
- (setq pt11 (car mid1)
- pt12 (cadr mid1)
- n1 (caddr mid1)
- pt21 (car mid2)
- pt22 (cadr mid2)
- n2 (caddr mid2)
- intersections nil
- )
- (cond ((= n1 n2 0.0) ;_直线交直线
- (list (inters pt11 pt12 pt21 pt22 nil))
- )
- ((and (= n1 0.0) (/= n2 0.0)) ;_直线交圆弧
- (setq ptcr2 (SS-PTC-ptcR pt21 pt22 n2))
- (L_INT_C pt11 pt12 (car ptcr2) (cadr ptcr2))
- )
- ((and (/= n1 0.0) (= n2 0.0)) ;_圆弧交直线
- (setq ptcr1 (SS-PTC-ptcR pt11 pt12 n1))
- (L_INT_C pt21 pt22 (car ptcr1) (cadr ptcr1))
- )
- ((and (/= n1 0.0) (/= n2 0.0)) ;_圆弧交圆弧
- (setq ptcr1 (SS-PTC-ptcR pt11 pt12 n1)
- ptcr2 (SS-PTC-ptcR pt21 pt22 n2)
- )
- (c_int_c (car ptcr1) (cadr ptcr1) (car ptcr2) (cadr ptcr2))
- )
- )
- )
- ;;;---------------------------------------------------------------------;;;
- ;;;此函数2010.07.06改版,注意其他程序
- (defun gsls-ang-trans (ang)
- (while (> ang pi)
- (setq ang (- ang pi))
- )
- (while (< ang 0.0)
- (setq ang (+ ang pi))
- )
- ang
- )
- ;;;---------------------------------------------------------------------;;;
- ;;;用到WK函数
- ;___________________直线与圆交点函数,输入值直线端点1,端点2,圆心,半径.返回值交点表
- (defun L_INT_C (l_end1 l_end2 c_cen c_rad / pedal dist_cen_l int1 int2
- ints)
- (setq pedal (pedal_to_line c_cen l_end1 l_end2)
- dist_cen_l (distance pedal c_cen))
- (cond
- ((equal c_rad dist_cen_l min_num) (setq ints (list pedal)))
- ((> c_rad dist_cen_l)
- (progn
- (setq int1
- (polar pedal
- (angle l_end1 l_end2)
- (sqrt (- (* c_rad c_rad) (* dist_cen_l dist_cen_l)))
- )
- )
- (setq int2
- (polar pedal
- (+ pi (angle l_end1 l_end2))
- (sqrt (- (* c_rad c_rad) (* dist_cen_l dist_cen_l)))
- )
- )
- (setq ints (list int1 int2))
- )
- )
- )
- ints
- )
- ;;;点到直线的垂足坐标
- (defun pedal_to_line (pt pt1 pt2)
- (inters
- pt
- (polar pt (+ (/ pi 2) (angle pt1 pt2)) 1000)
- pt1
- pt2
- nil
- )
- )
- ;_精度设置_________________________________________________
- (setq min_num 1e-7)
- ;___________________圆与圆交点函数,输入值圆心1,半径1,圆心2,半径2.返回值交点表
- (defun c_int_c (c1_cen c1_rad c2_cen c2_rad / ints c1c2_dis dd ee)
- (setq c1c2_dis (distance c1_cen c2_cen))
- (cond
- ((equal c1c2_dis (+ c1_rad c2_rad) min_num)
- (setq ints (list (polar c1_cen (angle c1_cen c2_cen) c1_rad)))
- )
- ((equal c1c2_dis (abs (- c1_rad c2_rad)) min_num)
- (if (minusp (- c1_rad c2_rad))
- (setq ints (list (polar c2_cen (angle c2_cen c1_cen) c2_rad)))
- (setq ints (list (polar c1_cen (angle c1_cen c2_cen) c1_rad)))
- )
- )
- ((and (> c1c2_dis (abs (- c1_rad c2_rad)))
- (< c1c2_dis (+ c1_rad c2_rad))
- )
- (progn
- (setq dd (/ (- (+ (* c1c2_dis c1c2_dis) (* c1_rad c1_rad))
- (* c2_rad c2_rad)
- )
- (* 2 c1c2_dis)
- )
- )
- (setq ee (sqrt (- (* c1_rad c1_rad) (* dd dd))))
- (setq
- ints (list (polar (polar c1_cen (angle c1_cen c2_cen) dd)
- (+ (angle c1_cen c2_cen) (/ pi 2))
- ee
- )
- )
- )
- (setq ints
- (append
- ints
- (list (polar (polar c1_cen (angle c1_cen c2_cen) dd)
- (- (angle c1_cen c2_cen) (/ pi 2))
- ee
- )
- )
- )
- )
- )
- )
- )
- ints
- )
- ;;;________________________________________________;;;
- ;;;---------------------------------------------------------------------;;;
- ;;;其他函数
- ;;;获取点集ptlst中与点pt距离最近的点
- (defun get-mindis-pt (ptlst pt)
- (car
- (vl-sort ptlst
- (function (lambda (e1 e2)
- (< (distance e1 pt) (distance e2 pt))
- )
- )
- )
- )
- )
- ;;;---------------------------------------------------------------------;;;
- ;;;参考qj_chen表项替代函数改进
- ;;;表项替换,支持2重表,当指定i为list如(3 1)时,替换第3个子表中的第1个元素
- (defun ch-lst (new i lst / j len fst mid)
- (if (/= (type i) 'list)
- (cond
- ((minusp i)
- lst
- )
- ((> i (setq len (length lst)))
- lst
- )
- ((> i (/ len 2))
- (reverse (ch-lst new (1- (- len i)) (reverse lst)))
- )
- (t
- (append
- (progn
- (setq fst nil)
- (repeat (rem i 4)
- (setq fst (cons (car lst) fst)
- lst (cdr lst)
- )
- )
- (repeat (/ i 4)
- (setq fst (cons (cadddr lst)
- (cons (caddr lst)
- (cons
- (cadr lst)
- (cons
- (car lst)
- fst
- )
- )
- )
- )
- lst (cddddr lst)
- )
- )
- (reverse fst)
- )
- (list new)
- (cdr lst)
- )
- )
- )
- (progn
- (setq j (cadr i)
- i (car i)
- )
- (if j
- (progn
- (setq mid (nth i lst))
- (setq mid (ch-lst new j mid))
- (ch-lst mid i lst)
- )
- (ch-lst new i lst)
- )
- )
- )
- )
- ;;;---------------------------------------------------------------------;;;
- ;;;用到 吴所不及 函数
- ;;;转换选择集为表
- (defun wjm_ss2lst (ss / i e lst)
- (if (= (type ss) 'PICKSET)
- (progn
- (setq i -1)
- (while (setq e (ssname ss (setq i (1+ i))))
- (if (= (type e) 'ENAME) (setq lst (cons e lst)) nil)
- )
- lst
- )
- nil
- )
- )
如有问题请采用下列代码将问题图元表贴出 - ;;;实体与字符串互换
- (defun obj->str (ent / relst mid ent)
- (setq relst (list -1 330 330 5 100 100 102 102 410))
- (setq mid (print ent))
- (foreach num relst
- (progn
- (setq mid (vl-remove (assoc num mid) mid))
- )
- )
- (vl-prin1-to-string mid)
- )
- (defun c:tt ()
- (obj->str (entget (car (entsel)) '("*")))
- (princ)
- )
|
评分
-
查看全部评分
|