本帖最后由 自贡黄明儒 于 2014-11-7 09:43 编辑
;;164.1 [功能] 曲线是否封闭
;;164.2 [功能]使多段线封闭
;;164.3 [功能] 多段线端点列表
;;164.4 [功能] 矩形中点坐标
;;164.5 [功能] 参数param处的切线方向的角度
;;164.6 [功能] 参数param处的法线方向的角度
;;164.7 [功能] 曲线一点的切线方向的角度
;;164.8 [功能] 曲线一点的法线方向的角度
;;164.9 [功能] 去除多段线重点
;;164.10 [功能] 判断点是否在曲线上
;;164.11 [功能] 曲线长度
;;164.12 [功能] 多段线子段数量
;;164.13 [功能] 曲线中点
;;164.14 [功能] 曲线一点的参数param
;;164.15 [功能] 参数param处的坐标
;;164.16 [功能] 多段线第n子段的起点坐标
;;164.17 [功能] 多段线第n子段的终点坐标
;;164.18 [功能] 多段线所点击子段的两端点列表
;;164.19 [功能] 多段线所点击点最近的一个顶点
;;164.20 [功能] 多段线所点击子段param(索引)
;;164.21 [功能] 多段线所点击子段的起点坐标
;;164.22 [功能] 多段线所点击子段的终点坐标
;;164.23 [功能] 多段线所击点离起点近
;;164.24 [功能] 多段线所点击子段否是直线(返回nil是弧)
;;164.25 [功能] 求多段线上的弧段(圆或圆弧也有效)的圆心 by caoyin
;;164.26 [功能] 求多段线上的弧段(圆或圆弧也有效)的圆心
;;164.27 [功能] 判断多段线是否有圆弧(凸度/=0)的子段
;;164.28 [功能] 判断多段线是否有圆弧(凸度/=0)的子段
;;164.29 [功能] 连接线、弧成多段线
;;164.30 [功能] 构造矩形 by highflybird
;;164.31 [功能] 点表生成多段线
;;164.32 [功能] 3D多段线
;;164.33 [功能] 多段线反向(起点反成终点) byzml84
;;164.34 [功能] 多段线删除顶点
;;164.35 [功能] 多段线增加顶点
;;164.36 [功能] 多段线修改顶点
;;164.37 [功能] 多段线拷贝子段
;;164.38 [功能] 修改多段线子段
;;164.39 [功能] 修改多段线子段为直线
;;164.40 [功能] 点在封闭多段线内返回T,其余nil By 狂刀
;;164.41 [功能] 点在封闭多段线内返回T,其余nil By SmcTools
;;164.42 [功能] 判断点在封闭曲线内外,自交曲线不适用 By Gu_xl
;;164.43 [功能] 点在封闭多段线内返回T;线上0;外nil
;;164.44 [功能] 多段线弧段全改为直线段
;;164.45 [功能] 沿多段线取点,弧处按角度加密取点
;;164.46 [功能] 多段线自相交 by st788796;;164.33 [功能] 多段线删除顶点 By 自贡黄明儒
(defun HH:delLwpolyPt (/ EN ENT L1 L2 P P1 P2 P90 SS X Y)
(setq p1 (getpoint))
(setq p2 (getcorner p1))
(if (setq ss (ssget "C" p1 p2 '((0 . "LWPOLYLINE"))))
(progn
(setq en (ssname ss 0))
(setq ENT (entget EN))
(if (> (setq P90 (cdr (assoc 90 ent))) 2)
(progn
(setq p (mapcar '(lambda (X Y) (/ (+ X Y) 2.0)) p1 p2))
(setq p (vlax-curve-getclosestpointto en (trans p 1 0)))
(setq p1 (HH:PickClosePt en p))
(setq p1 (list 10 (car p1) (cadr p1)))
(setq L2 (cddddr (member p1 ent))) ;后段
(setq L1 (reverse (cdr (member p1 (reverse ent))))) ;前段
(setq ent (append L1 L2))
(entmod (subst (cons 90 (1- P90)) (assoc 90 ent) ent))
)
)
)
)
)
;;示例(HH:delLwpolyPt1 (car(setq en(entsel))) (cadr en)) By 自贡黄明儒
(defun HH:delLwpolyPt1 (en p / ENT L1 L2 P1)
(setq ENT (entget en))
(setq p (vlax-curve-getclosestpointto en (trans p 1 0)))
(setq p1 (HH:PickClosePt en p)) ;离p最近的顶点
(setq p1 (list 10 (car p1) (cadr p1)))
(setq L2 (cdr (member p1 ent))) ;后段
(setq L1 (reverse (cdr (member p1 (reverse ent))))) ;前段
(entmod (append L1 L2))
)
;;164.34 [功能] 多段线增加顶点 By 自贡黄明儒
;;示例(HH:LwAddVertex (car(setq en(entsel))) (cadr en))
(defun HH:LwAddVertex (en pt / EN GR N PP)
;;增加一个顶点
(defun LwAddVertex (obj index pt bugle sw ew)
(vlax-invoke obj 'addvertex index pt)
(vla-setbulge obj index bugle)
(vla-setwidth obj index sw ew)
)
(setq pp (vlax-curve-getClosestPointTo en (trans pt 1 0)))
(setq n (fix (vlax-curve-getParamAtPoint en pp)))
(setq obj (vlax-ename->vla-object en))
(vla-GetWidth obj n 'sw 'ew)
(setq pp (getpoint "\n 新增点 "))
(setq pp (mapcar '+ '(0 0) pp))
(vl-catch-all-apply 'LwAddVertex (list obj (1+ n) pp 0 sw sw))
)
;;164.35 [功能] 多段线修改顶点 By 自贡黄明儒
;;示例(HH:ModifyVertex (car(setq en(entsel))) (cadr en) (getpoint))
(defun HH:ModifyVertex (en pt newPt / ENT L1 L2 NPT P P10)
(setq p (HH:PickClosePt en pt))
(setq p10 (list 10 (car p) (cadr p)))
(setq ent (entget en))
(setq L2 (cdr (member p10 ent)))
(setq L1 (reverse (cdr (member p10 (reverse ent)))))
(setq Npt (list (list 10 (car newPt) (cadr newPt))))
(entmod (append L1 Npt L2))
)
;;(HH:ModifyVertex1 (car(setq en(entsel))) (cadr en)) By 自贡黄明儒
(defun HH:ModifyVertex1 (en p / ENT GR L1 L2 NPT P10)
(setq ent (entget en))
(setq pt (HH:PickClosePt en p))
(setq p10 (list 10 (car pt) (cadr pt)))
(setq L2 (cdr (member p10 ent)))
(setq L1 (reverse (cdr (member p10 (reverse ent)))))
(while (and (setq gr (grread 5)) (= (car gr) 5))
(setq Npt (list (list 10 (car (cadr gr)) (cadr (cadr gr)))))
(entmod (append L1 Npt L2))
)
)
;;164.36 [功能] 多段线拷贝子段 By 自贡黄明儒
;;(HH:CopyLwSeg (car(setq en(entsel))) (cadr en))
(defun HH:CopyLwSeg (en p / ENT L0 L1 L2 LASTENT N P1 PP TEM)
(setq pp (vlax-curve-getClosestPointTo en p))
(setq n (fix (vlax-curve-getParamAtPoint en pp)))
(setq p1 (vlax-curve-getPointAtParam en n))
(setq p1 (list 10 (car p1) (cadr p1)))
(setq ent (entget en))
(setq tem (member p1 ent))
(repeat 8 (setq L0 (cons (car tem) L0)) (setq tem (cdr tem)))
(setq L0 (reverse L0))
(setq L2 (list (last tem)))
(setq L1 (list
'(0 . "LWPOLYLINE")
'(100 . "AcDbEntity")
'(100 . "AcDbPolyline")
'(90 . 2)
)
)
(entmake (append L1 l0 L2))
(setq Lastent (entlast))
(command "_.move" Lastent "" pp pause)
)
;;164.37 [功能] 修改多段线子段 By 自贡黄明儒
;;示例(HH:ModifySeg (car(setq en(entsel))) (cadr en))
(defun HH:ModifySeg (en p / ENT GR I L1 L2 N P1 P2 P42 PP X Y)
;;133.1 [功能] 旋转一个点(见113)
;;Rotate 'pnt'点 from a base point of 'p1' and through an angle of 'ang' (in radians)
(defun MJ:rotate_pnt (pnt p1 ang)
(polar p1 (+ (angle p1 pnt) ang) (distance p1 pnt))
)
;;两点之中点
(defun mid (p1 p2 / X Y)
(mapcar '(lambda (X Y) (/ (+ X Y) 2.0)) p1 p2)
)
;;已知三点p1 p2 p,求组码42
(defun my42 (p1 p2 pt / CEN D H P1P2 P1T P2P1 PT1 R)
(setq d (/ (distance p1 p2) 2.0))
(setq p1p2 (mid p1 p2))
(setq p2p1 (MJ:rotate_pnt p1 p1p2 (/ pi 2)))
(setq pt1 (mid p1 pt))
(setq p1t (MJ:rotate_pnt p1 pt1 (/ pi 2)))
(setq cen (inters p1p2 p2p1 pt1 p1t nil))
(setq h (car (trans (mapcar '- cen p1) 0 (mapcar '- p1 p2))))
(setq r (distance cen p1))
(if (MINUSP h)
(setq r (+ r h))
(setq r (- h r))
)
(/ r d)
)
(setq pp (vlax-curve-getClosestPointTo en p))
(setq n (fix (vlax-curve-getParamAtPoint en pp)))
(setq p1 (vlax-curve-getPointAtParam en n))
(setq p2 (vlax-curve-getPointAtParam en (1+ n)))
(setq ent (entget en))
(setq i 0)
(while (or (/= (caar ent) 42)
(if (< i n)
(setq i (1+ i))
)
)
(setq L1 (cons (car ent) L1)
ent (cdr ent)
)
)
(setq L1 (REVERSE L1))
(setq L2 (cdr ent))
(while (and (setq gr (grread 5)) (= (car gr) 5))
(setq p42 (cons 42 (my42 p1 p2 (cadr gr))))
(entmod (append L1 (list p42) L2))
)
(princ)
)
;;164.38 [功能] 修改多段线子段为直线 By 自贡黄明儒
;;(HH:ModifySegLine (car(setq en(entsel))) (cadr en))
(defun HH:ModifySegLine (en p / ENT I L1 L2 N P1 P2 PP)
(setq pp (vlax-curve-getClosestPointTo en p))
(setq n (fix (vlax-curve-getParamAtPoint en pp)))
(setq p1 (vlax-curve-getPointAtParam en n))
(setq p2 (vlax-curve-getPointAtParam en (1+ n)))
(setq ent (entget en))
(setq i 0)
(while (or (/= (caar ent) 42)
(if (< i n)
(setq i (1+ i))
)
)
(setq L1 (cons (car ent) L1)
ent (cdr ent)
)
)
(setq L1 (REVERSE L1))
(setq L2 (cdr ent))
(entmod (append L1 (list (cons 42 0)) L2))
(princ)
)
;;164.39.1 [功能] 点在封闭多边形内返回T;线上0;外nil
;;改编自 狂刀的程序(应该简洁而完美) By 自贡黄明儒
;;(PtInorOut1 (car (entsel)) (getpoint))
(defun PtInorOut1 (en pt / P1 P2 PP PT PTS)
(setq pp (vlax-curve-getClosestPointTo en pt))
(if (equal pp pt 0.00001)
0
(progn
(setq pts (HH:PtLists en))
(setq pts (MAPCAR '(LAMBDA (p1 p2) (REM (- (ANGLE pt p1) (ANGLE pt p2)) PI))
(CONS (LAST pts) pts)
pts
)
)
(equal (ABS (APPLY '+ pts)) PI)
)
)
)
;;164.39.2 [功能] 点在封闭多边形内返回T,其余nil By SmcTools
;;(PtInorOut2 (car(entsel))(getpoint))
(defun PtInorOut2 (en pt / I N PT_LIST VA VA_COUNT)
(setq pt_list (HH:PtLists en))
(setq i 0
va_count 0
n (length pt_list)
pt_list (append pt_list (list (car pt_list)))
)
(repeat n
(setq va (- (angle pt (nth i pt_list))
(angle pt (nth (1+ i) pt_list))
)
)
(cond ((> va pi) (setq va (- va pi)))
((< va (* -1 pi)) (setq va (+ va pi)))
)
(setq va_count (+ va_count va)
i (1+ i)
)
)
(equal (abs va_count) pi)
)
;;164.40 [功能] 判断点在封闭曲线内外,自交曲线不适用 By Gu_xl 2012.07.31
;;返回: 点在封闭曲线内返回T;线上0;外nil
;;测试: (gxl-PtInCurveP (car(entsel "\n选择曲线:")) (getpoint))
(defun gxl-PtInCurveP (POLY PT / CP LW MINP MAXP MINX
MINY MAXX MAXY X Y LST CLOCKWISEP
ENDPARAM CURVELENGTH PARAM DIST D1 D2
DEV
)
(cond
((equal pt (vlax-curve-getclosestpointto poly pt) 1e-8) 0) ;_ 点在曲线上 T
((progn
(vla-GetBoundingBox
(setq lw (vlax-ename->vla-object POLY))
'MinP
'MaxP
)
(setq MinP (vlax-safearray->list MinP))
(setq MaxP (vlax-safearray->list MaxP))
(setq minx (car MinP)
miny (cadr MinP)
maxx (car MaxP)
maxy (cadr MaxP)
x (car pt)
y (cadr pt)
)
(or (< x minx)
(> x maxx)
(< y miny)
(> y maxy)
)
)
NIL ;_ 点在曲线最小包围盒外 nil
)
(t
(setq
lst (mapcar
(function
(lambda (x)
(vlax-curve-getParamAtPoint
lw
(vlax-curve-getClosestPointTo lw x)
)
)
)
(list minp
(list minx maxy)
MaxP
(list maxx miny)
)
)
) ;_ 最小包围盒点在曲线上的投影点的参数表
(setq ClockwiseP
(if (or
(<= (car lst) (cadr lst) (caddr lst) (cadddr lst))
(<= (cadr lst) (caddr lst) (cadddr lst) (car lst))
(<= (caddr lst) (cadddr lst) (car lst) (cadr lst))
(<= (cadddr lst) (car lst) (cadr lst) (caddr lst))
) ;_ or
t
) ;_ if
) ;_ 判断曲线是否为顺时针,顺时针 = T
(setq endparam (vlax-curve-getendparam poly)
curvelength (vlax-curve-getDistAtParam poly endparam) ;_ 曲线长度
)
(setq param (vlax-curve-getparamatpoint poly cp)
dist (vlax-curve-getDistAtParam poly param)
)
(if (equal param (fix param) 1e-8)
(progn
(setq d1 (- dist 1e-8))
(if (minusp d1)
(setq d1 (+ curvelength d1))
)
(setq d2 (+ dist 1e-8))
(if (> d2 curvelength)
(setq d2 (- d2 curvelength))
)
(if (< (distance pt (vlax-curve-getpointatdist poly d1))
(distance pt (vlax-curve-getpointatdist poly d2))
)
(setq param (vlax-curve-getparamatdist poly d1))
(setq param (vlax-curve-getparamatdist poly d2))
)
)
)
(setq dev (vlax-curve-getFirstDeriv poly param)
cp (vlax-curve-getpointatparam poly param)
)
(= ClockwiseP
(
(lambda (p1 p2 p3)
(<
(* (- (car p2) (car p1)) (- (cadr p3) (cadr p1)))
(* (- (cadr p2) (cadr p1)) (- (car p3) (car p1)))
)
)
pt
cp
(mapcar '+ cp dev)
)
)
)
)
)
;;164.41.1 [功能] 点在封闭曲线内返回T;线上0;外nil
;;封闭曲线必须全可见,还是caoyin的那个程序好 By 自贡黄明儒
;;(PtInorOut (car(entsel))(getpoint))
(defun PtInorOut (en p / AREA AREA1 EN1 PP)
(setq pp (vlax-curve-getclosestpointto en (trans p 1 0)))
(if (equal pp p 0.00001)
0
(progn
(setq area (vlax-get (vlax-ename->vla-object en) 'area))
(command "_.offset" "" en p "");用(vla-offset obj 0.00001)比较距离
(setq area1 (vlax-get (vlax-ename->vla-object en1) 'area))
(entdel en1)
(> area1 area)
)
)
)
;;164.41.2 [功能] 点在封闭多段线内返回T;线上0;外nil
;;封闭曲线必须全可见
;;(PtInorOut3 (car(entsel))(getpoint))
(defun PtInorOut3 (en p / EN1 PP SS)
(setq pp (vlax-curve-getclosestpointto en (trans p 1 0)))
(if (equal pp p 0.00001)
0
(progn
(entmake (list '(0 . "POINT") (cons 10 p)))
(setq en1 (entlast))
(if (and (setq ss (ssget "wp" (HH:PtLists en)))
(ssmemb en1 ss)
)
(setq ss T)
)
(entdel en1)
ss
)
)
)
;;164.42 [功能] 多段线弧段全改为直线段 By 自贡黄明儒
;;(HH:ModifySegLine1 (car(setq en(entsel))))
(defun HH:ModifySegLine1 (en / X)
(entmod
(mapcar '(lambda (x)
(if (equal (car x) 42)
(cons 42 0)
x
)
)
(entget en)
)
)
)
;;多段线自相交 by st788796
(defun rrr (e / getlst ep obj pts ptl pams il)
(defun Getlst (n / i il)
(setq i (fix n))
(repeat i (setq il (cons (setq n (1- n)) il)))
il
)
(setq obj (vlax-ename->vla-object e)
ep (vlax-curve-getendparam e)
)
(if (setq pts (vlax-invoke obj 'IntersectWith obj 0))
(progn
(while pts
(setq ptl (cons (list (car pts) (cadr pts) (caddr pts)) ptl)
pts (cdddr pts)
)
)
(setq il (cdr (getlst ep))
pams (mapcar '(lambda (x)
(vlax-curve-getparamatpoint e x)
)
ptl
)
)
(if (vlax-curve-isclosed e)
(not (equal (reverse pams)
(cons 1. (cons 0. (cdr il)))
)
)
(not (equal (vl-remove '0. (reverse pams)) il)) ;_假闭合情况
)
)
)
) |