曲线之间的交点
大家好,我刚刚探索了vlax曲线-***函数,出现了一个问题:
有可能找到两条曲线之间的交点吗?
为什么不是VLAX-INTERSECTWITH
(setq intpt2 (vlax-invoke obj3 'intersectWith obj1 acExtendThisEntity))
谢谢你,比格尔!
看起来比我想象的要容易。 不用担心,有4个条件你可以使用扩展是1可以使用1 2 3 4而不是长acex。。。。 我在代码方面取得了一些进展:
(defun c:test ( / ent1 ent2 obj1 obj2 int-lst cnt pt pt-lst )
(vl-load-com)
(setvar 'errno 0)
(while
(not
(and
(setq ent1 (car (entsel "\nPick first curve: ")))
(setq obj1 (vlax-ename->vla-object ent1))
)
)
(if (or (= (getvar 'errno) 7) (null ent1)) (princ "\nYou missed, try again!") )
)
(while
(not
(and
(setq ent2 (car (entsel "\nPick second curve: ")))
(setq obj2 (vlax-ename->vla-object ent2))
(not (eq ent1 ent2))
)
)
(if (or (= (getvar 'errno) 7) (null ent2) ) (princ "\nYou missed, try again!") )
)
(setq int-lst (vlax-safearray->list (vlax-variant-value (vla-IntersectWith obj1 obj2 acExtendNone))))
(setq cnt (- 1))
(foreach x int-lst
(if
(and
(setq pt (list (nth (setq cnt (+ cnt 1)) int-lst) (nth (setq cnt (+ cnt 1)) int-lst) (nth (setq cnt (+ cnt 1)) int-lst)))
(car pt) ; X check
(cadr pt) ; Y check
(caddr pt) ; Z check
)
(setq pt-lst (cons pt pt-lst))
)
)
(setq pt-lst (reverse pt-lst))
(progn
(setvar 'PDMODE 35)
(foreach x pt-lst
(if x
(progn
(entmakex (list (cons 0 "POINT") (cons 10 x) (cons 62 1)))
(princ "\n")(print x)
)
)
)
)
(princ)
);defun
我不确定我的方法是否草率。
我要考虑的下一步是使用选择集:
-SSGET(cons 0“圆、弧、*线*)
-通过选择集迭代并对每个实体使用置换,直到找到所有交点 下面是下一个版本(在我脑海中):
; Prompts for a SS (either implied or user) until theres one:
(defun C:test ( / SS SSloop lst assoc-lst cnt )
(setq SSloop T)
(while SSloop
(if (not (setq SS (ssget "_I")))
(setq SS (ssget "_:L"))
(sssetfirst nil nil)
)
(if (and SS (>= (sslength SS) 1))
(progn
(setq lst (ss->lst SS))
(setq assoc-lst (combine-itms lst))
(print assoc-lst)
(setq cnt 0)
(repeat (length assoc-lst)
(ins-pt (car (nth cnt assoc-lst)) (cdr (nth cnt assoc-lst)) )
(setq cnt (+ cnt 1))
)
(setq SSloop nil)
)
)
)
(princ)
)
(defun ss->lst (ss / i l)
(if (eq (type ss) 'pickset)
(repeat (setq i (sslength ss))
(setq l (cons (ssname ss (setq i (1- i))) l))
)
)
)
; So this is the source list: A B C D
; The result should be like this: (("A" . "B") ("A" . "C") ("A" . "D") ("B" . "C") ("B" . "D") ("C" . "D"))
; So there would be combination between every 2 items
(defun combine-itms ( lst / oldlst newlst cnt itm )
; (setq lst (list "A" "B" "C" "D"))
(setq oldlst lst)
(setq newlst (list)) ; the result should be: AB AC AD BC BD CD
(setq cnt 0) ; set a counter
(while (> (length lst) 0) ; repeat until all the items are removed from the list
(foreach x oldlst ; iterate trough the list
(if
(and
(not (eq (nth cnt lst) x)) ; check if the current item doesnt duplicate itself (example result would be: AA BB CC DD)
(not (member (cons (nth cnt lst) x) newlst ))
(not (member (cons x (nth cnt lst)) newlst ))
lst ; check if the lst is not nil
)
(progn
(setq itm
(cons
(nth cnt lst) ; the current item
x ; iteration item
)
) ; combined item
(setq newlst (cons itm newlst)) ; add the combined item in a new list
)
)
); foreach
(setq lst (remove_nth lst cnt)) ; returns the same list without the item on "cnt" position (redefine the list)
;(setq cnt (+ cnt 1)) ; increment the counter
); repeat
(setq newlst (reverse newlst))
; (print newlst)
; (princ)
)
; LM - remove nth (returns the same list with the removed item):
(defun remove_nth ( lst n / lstn )
(setq n (1+ n))
(foreach x lst (if (/= 0 (setq n (1- n))) (setq lstn (cons x lstn))))
(reverse lstn)
)
(defun ins-pt ( ent1 ent2 / obj1 obj2 int-lst cnt pt pt-lst )
; (setq ent1 (car (entsel "\nPick first curve: ")))
(setq obj1 (vlax-ename->vla-object ent1))
; (setq ent2 (car (entsel "\nPick second curve: ")))
(setq obj2 (vlax-ename->vla-object ent2))
(setq int-lst (vlax-safearray->list (vlax-variant-value (vla-IntersectWith obj1 obj2 acExtendNone))))
(setq cnt (- 1))
(foreach x int-lst
(if
(and
(setq pt (list (nth (setq cnt (+ cnt 1)) int-lst) (nth (setq cnt (+ cnt 1)) int-lst) (nth (setq cnt (+ cnt 1)) int-lst)))
(car pt) ; X check
(cadr pt) ; Y check
(caddr pt) ; Z check
)
(setq pt-lst (cons pt pt-lst))
)
)
(setq pt-lst (reverse pt-lst))
(progn
(setvar 'PDMODE 35)
(foreach x pt-lst
(if x
(progn
(entmakex (list (cons 0 "POINT") (cons 10 x) (cons 62 1)))
; (princ "\n")(print x)
)
)
)
)
(princ)
);defun
我必须自己编写这个“合并itms”子函数。。总的来说,代码非常凌乱,可能可以缩短(也将我以前的代码修改为名为“ins pt”的子函数)。
我所知道的唯一与此类似的代码是CAB的“Break.lsp”,但我没有花时间分析它(只是直接尝试了我的想法)。 尝试将上述表达式用于两个不相交的对象-注意,空safearray的上界为负。
以下是两种解决方案:
https://www.theswamp.org/index.php?topic=43461.msg486965#msg486965
您可能还会发现这些旧函数很有用:
http://lee-mac.com/intersectionfunctions.html
谢谢李,
我仍然缺乏“安全阵列”的知识(只是无法想象它到底代表了什么)。
我知道你的交集函数,但我尝试“重写”这一函数作为练习。。现在重新检查代码,代码缩短了4-5倍
无论如何,我试图创建类似的函数,比如“LM:intersectionsinset”,它将返回一个如下的assoc列表:
((点交点列表)(切线角度列表-第一条inters曲线)(切线角度列表-第二条inters曲线))
这将允许在这些点插入/创建对象,并切换旋转(在第一条曲线或第二条曲线上对齐)。 如附图所示,是否有助于改善相交曲线
测验图纸
到目前为止,没有任何回复,似乎不可能在我的情况下获得交点
页:
[1]
2