我们有:
1) 很明显,圆在边界内。
2) 圆必须至少在两个位置接触边界。 谢谢你的建议。
李,我试着看一看,但我认为这(对我来说)会很难。。。 正如我所料,修改李的代码对我来说非常困难。
我走了另一条路,也许并不完美,但它解决了我的问题。
笔记:
-增加步骤1的值以获得更大的结果确定性
-我认为step1=60是一段很好的关系时间/准确性
-函数LM:LWPoly->lisp MinimumEnclosingCircle列表(Lee Mac)而不是我的Vert\u poly也描述了多段线的曲线,如果插入lisp,也可以使用曲线多段线进行检查。
最后,对不起我的英语。
(defun C:TEST (/ Dx Dy Lp List_vert_poly list_p_int P_center dist)
(prompt "\nSelect Polyline: ")
(setq POLY_vl (vlax-ename->vla-object (ssname (ssget ":S" '((0 . "POLYLINE,LWPOLYLINE"))) 0)))
(Vert_poly)
(grid_1)
(Point_int)
(Point_center)
(repeat 3
(grid_2)
(Point_center)
)
(entmake
(list
(cons 0 "CIRCLE")
(cons 8 (getvar "clayer"))
(cons 10 P_center)
(cons 40 dist)
)
)
(princ)
)
; Returns a list of polyline vertices
(defun Vert_poly (/ n_par pt)
(setq list_vert_poly nil)
(setq n_par (fix (vlax-curve-getendparam POLY_vl)))
(repeat n_par
(setq pt (vlax-curve-getpointatparam POLY_vl (setq n_par (1- n_par))))
(setq list_vert_poly (cons pt list_vert_poly))
(if (/= (last pt) 0.0)
(progn
(alert (strcat "Invalid Object Selected"
"\nz-coordinate vertices not = 0.0"))
(exit)
)
)
)
)
; Returns a grid of points within the BoundingBox of the selected poly
(defun grid_1 (/ P1_ P2_ n P> step1)
(setq step1 60)
(vla-getboundingbox POLY_vl 'p1 'p2)
(setq P1_ (vlax-safearray->list p1))
(setq P2_ (vlax-safearray->list p2))
(setq P1_ (list (car P1_) (cadr P1_)))
(setq P2_ (list (car P2_) (cadr P2_)))
(setq Dx (/ (- (car P2_) (car P1_)) step1))
(setq Dy (/ (- (cadr P2_) (cadr P1_)) step1))
(setq n 0)
(setq P> P1_)
(setq Lp (list P1_))
(repeat (* (1+ step1) step1)
(setq P> (list (+ (car P>) Dx) (cadr P>)))
(setq Lp (cons P> Lp))
(setq n (1+ n))
(if (= n step1)
(progn
(setq n 0)
(setq P1_ (list (car P1_) (+ (cadr P1_) Dy)))
(setq P> P1_)
(setq Lp (cons P> Lp))
)
)
)
)
; Returns a grid of dots around the center point (provisional)
(defun grid_2 (/ P1_ step2 P> n)
(setq step2 30)
(setq list_p_int nil)
(setq P1_ (list (- (car P_center) Dx) (- (cadr P_center) Dy)))
(setq Dx (/ (* 2 Dx) step2))
(setq Dy (/ (* 2 Dy) step2))
(setq n 0)
(setq P> P1_)
(setq list_p_int (list P1_))
(repeat (* (1+ step2) step2)
(setq P> (list (+ (car P>) Dx) (cadr P>)))
(setq list_p_int (cons P> list_p_int))
(setq n (1+ n))
(if (= n step2)
(progn
(setq n 0)
(setq P1_ (list (car P1_) (+ (cadr P1_) Dy)))
(setq P> P1_)
(setq list_p_int (cons P> list_p_int))
)
)
)
)
; Returns the list of points inside the polyline
(defun Point_int (/ P_distant n Pr cont attr p# Pa Pa_ Pb )
(setq P_distant (polar (car Lp) 0 10000000))
(setq list_p_int nil)
(repeat (setq n (length Lp))
(setq Pr (nth (setq n (1- n)) Lp))
(setq cont -1)
(setq attr 0)
(setq p# nil)
(setq Pa (nth (setq cont (1+ cont)) list_vert_poly))
(setq Pa_ Pa)
(repeat (length list_vert_poly)
(setq Pb (nth (setq cont (1+ cont)) list_vert_poly))
(if (= cont (length list_vert_poly)) (setq Pb Pa_))
(setq P# (inters Pa Pb Pr P_distant))
(if (/= P# nil) (setq attr (1+ attr)))
(setq Pa Pb)
)
(if (> (rem attr 2) 0) (setq list_p_int (cons Pr list_p_int)))
)
)
; Returns the farthest point from the polyline
(defun Point_center (/ Pa n Pvic)
(setq Dist 0.0000001)
(setq P_center nil)
(repeat (setq n (length list_p_int))
(setq Pa (nth (setq n (1- n)) list_p_int))
(setq Pvic (vlax-curve-getClosestPointTo POLY_vl Pa))
(if (> (distance Pa Pvic) Dist)
(progn
(setq P_center Pa)
(setq Dist (distance Pa Pvic))
)
)
)
)
(vl-load-com)
(princ)
漂亮的GP\U 谢谢pBe
页:
1
[2]