本帖最后由 自贡黄明儒 于 2013-11-23 15:27 编辑
llsheng_73 发表于 2013-11-23 13:26
十分感谢老黄,不过测试了一下狂刀的,代码精简那是没法比,但是对于相交于一条边上的时候会判断为非自交 ...
你的意思狂刀的也有bug?想怎么做呢?是不是上面说的B
- ;;[功能] 多段线自相交
- ;; (plinsp (car(entsel)))
- (defun plinsp (en / FLAG LAPT N O PTS PTS1 STPT)
- ;;52.1 [功能] 3D点->2D点 By Caoyin
- (defun 3d->2d (3dpt)
- (mapcar '+ 3dpt '(0. 0.))
- )
- ;;52.4 [功能] 3D点列表->2D点列表
- (defun 3dlist->2dlist (3dplist)
- (mapcar '3d->2d 3dplist)
- )
- ;;52.5 [功能] 对表分段
- ;;(xl_div lst nom)表分段. -> 返回 分段的表. ------by 无痕.2004.1
- ;; lst = 表,nom = 分段的子表元素个数(从1开始计).
- ;;示例 (xl_div '(1 2 3 4 5 6 7 8 9) 3) -> ((1 2 3) (4 5 6) (7 8 9))
- (defun xl-div (lst x / lst2)
- (foreach n lst
- (if (and lst2 (/= x (length (car lst2))))
- (setq lst2 (cons (append (car lst2) (list n)) (cdr lst2)))
- (setq lst2 (cons (list n) lst2))
- )
- )
- (reverse lst2)
- )
- ;;164.3 [功能] 多段线端点列表
- ;;示例(HH:PtLists (car (entsel)))
- (defun HH:PtLists (en)
- (mapcar 'cdr
- (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget en))
- )
- )
- ;;
- ;;(setq en (car (entsel)))
- (setq o (vlax-ename->vla-object en))
- (setq n (vlax-get o 'closed))
- (cond ((equal n 0)
- (setq laPt (vlax-curve-getEndPoint en))
- (setq stPt (vlax-curve-getStartPoint en))
- (setq pts (vlax-invoke o 'intersectwith o 0))
- (setq pts (3dlist->2dlist (xl-div pts 3)))
- (SETQ PTS1 (HH:PtLists EN))
- (foreach i pts
- (if (member i PTS1)
- (setq flag T)
- )
- )
- (or
- flag
- (/= (vlax-curve-getParamAtPoint en laPt)
- (vlax-curve-getendparam en)
- )
- (/= (vlax-curve-getParamAtPoint en stPt)
- (vlax-curve-getstartparam en)
- )
- (< (vlax-curve-getendparam en)
- (+ 1 (/ (length pts) 3))
- )
- )
- )
- (T nil)
- )
- )
|