aloy 发表于 2022-7-5 18:03:18

凸包

大家好,
在一个列表中,有n个点形成了一个凸包。我想用直线将它们首尾相连,并将它们转换为多段线。如何使用alisp/vlisp?。其思想是删除多边形形成的边界之外的所有线(如果有)。
提前感谢
芦荟

BIGAL 发表于 2022-7-5 18:18:52

你们现在可以在我的iPad上阅读列表作为pline序列的输入,但基本上是做一个
同时命令活动pline(第n X lst)
您应该可以在这里找到这段代码

aloy 发表于 2022-7-5 18:21:40

比加尔,
你能给我你提到的链接吗?。

BIGAL 发表于 2022-7-5 18:31:17

这是一个阅读列表并制作pline的循环示例,下面的代码是我头脑中未经测试的代码。这还取决于列表的组成方式。
 

(setq x 0)
(command "_pline")
(while (= (getvar "cmdactive") 1 )
(repeat (length lst)
(nth x lst)
(setq x (+ x 1))
)
)

aloy 发表于 2022-7-5 18:42:33

不起作用。我尝试了以下修改;它仍然要求声明点:
(defun testpline()
(setq x 0)
(setq np (length lst))
(command "_pline")
(while (and (= (getvar "cmdactive") 1 ) (< x np))
(repeat np
(nth x lst)
(setq x (+ x 1))
)
)
)
(setq lst '((5 5) (10 5) (10 10) (10 5) (5 5)))
但是,以下代码有效:
(defun polylines(pl)
   (setq p1 (car pl)
         p2(car (cdr pl)))
(command "pline" p1 p2 "")
(setq pl(cdr pl))
   (while (/= (car (cdr pl)) nil)
   (setq p3(car (cdr pl)))
   (command "pline" p2 p3 "")
   (command "pedit" (mid p1 p2) "j" (mid p2 p3) "" "")      
   (setq p1 p2
         p2 p3      
         pl (cdr pl))
   )
(princ)
)
(setq pl '((5 5) (10 5) (10 10) (5 10) (5 7) (5 5)))
(defun mid (a1 a2)
(list
   (/ (+ (car a1) (car a2)) 2.0)
   (/ (+ (cadr a1) (cadr a2)) 2.0)
)
)
这也不适用于以下3d列表:
(setq lst '((164304.0 91248.5 7.547) (164281.0 91262.4 7.381) (164281.0 91262.4 7.381) (164267.0 91269.9 7.881) (164259.0 91251.3 5.392) (164247.0 91236.3 5.086) (164235.0 91220.8 5.315) (164231.0 91211.8 5.332) (164222.0 91205.7 3.096) (164217.0 91197.1 5.072) (164211.0 91189.5 4.977) (164205.0 91181.2 5.01) (164188.0 91124.8 8.502) (164177.0 91127.7 11.429) (164167.0 91110.3 11.696) (164163.0 91101.0 11.925) (164157.0 91098.2 10.55) (164147.0 91086.1 10.418) (164134.0 91080.4 10.045) (164134.0 91080.4 10.045) (164127.0 91081.9 9.331) (164115.0 91086.9 9.352) (164102.0 91092.5 8.444) (164102.0 91092.5 8.444) (164086.0 91103.9 7.949) (164086.0 91103.9 7.949) (164069.0 91115.1 8.978) (164054.0 91128.7 11.494) (164035.0 91138.7 12.4) (164022.0 91143.3 14.446) (164009.0 91143.3 14.215) (163996.0 91142.8 14.327) (163984.0 91143.2 14.987) (163963.0 91141.1 15.749) (163951.0 91133.3 15.457) (163946.0 91130.7 15.605) (163943.0 91129.8 15.908) (163940.0 91110.7 12.691)))

这是使用我的代码片段生成的附图中给出的点集的上边界。
提款点。图纸

BIGAL 发表于 2022-7-5 18:47:34

试试这个

(setq lst '((164304.0 91248.5 7.547) (164281.0 91262.4 7.381) (164281.0 91262.4 7.381) (164267.0 91269.9 7.881) (164259.0 91251.3 5.392) (164247.0 91236.3 5.086) (164235.0 91220.8 5.315) (164231.0 91211.8 5.332) (164222.0 91205.7 3.096) (164217.0 91197.1 5.072) (164211.0 91189.5 4.977) (164205.0 91181.2 5.01) (164188.0 91124.8 8.502) (164177.0 91127.7 11.429) (164167.0 91110.3 11.696) (164163.0 91101.0 11.925) (164157.0 91098.2 10.55) (164147.0 91086.1 10.418) (164134.0 91080.4 10.045) (164134.0 91080.4 10.045) (164127.0 91081.9 9.331) (164115.0 91086.9 9.352) (164102.0 91092.5 8.444) (164102.0 91092.5 8.444) (164086.0 91103.9 7.949) (164086.0 91103.9 7.949) (164069.0 91115.1 8.978) (164054.0 91128.7 11.494) (164035.0 91138.7 12.4) (164022.0 91143.3 14.446) (164009.0 91143.3 14.215) (163996.0 91142.8 14.327) (163984.0 91143.2 14.987) (163963.0 91141.1 15.749) (163951.0 91133.3 15.457) (163946.0 91130.7 15.605) (163943.0 91129.8 15.908) (163940.0 91110.7 12.691)))
(setq x 0)
(command "_3dpoly")
(while (= (getvar "cmdactive") 1 )
(repeat (length lst)
(command (nth x lst))
(setq x (+ x 1))
))
(command "")

aloy 发表于 2022-7-5 18:58:29

是的,就是这样。需要加载给定的图形才能看到多段线。
谢谢。

(defun Bigal2(lst)
(setq lst '((164304.0 91248.5 7.547) (164281.0 91262.4 7.381) (164281.0 91262.4 7.381) (164267.0 91269.9 7.881) (164259.0 91251.3 5.392) (164247.0 91236.3 5.086) (164235.0 91220.8 5.315) (164231.0 91211.8 5.332)
    (164222.0 91205.7 3.096) (164217.0 91197.1 5.072) (164211.0 91189.5 4.977) (164205.0 91181.2 5.01) (164188.0 91124.8 8.502) (164177.0 91127.7 11.429) (164167.0 91110.3 11.696) (164163.0 91101.0 11.925)
    (164157.0 91098.2 10.55) (164147.0 91086.1 10.418) (164134.0 91080.4 10.045) (164134.0 91080.4 10.045) (164127.0 91081.9 9.331) (164115.0 91086.9 9.352) (164102.0 91092.5 8.444) (164102.0 91092.5 8.444)
    (164086.0 91103.9 7.949) (164086.0 91103.9 7.949) (164069.0 91115.1 8.978) (164054.0 91128.7 11.494) (164035.0 91138.7 12.4) (164022.0 91143.3 14.446) (164009.0 91143.3 14.215) (163996.0 91142.8 14.327)
    (163984.0 91143.2 14.987) (163963.0 91141.1 15.749) (163951.0 91133.3 15.457) (163946.0 91130.7 15.605) (163943.0 91129.8 15.908) (163940.0 91110.7 12.691)))
(setq x 0)
(command "_3dpoly")
(while (= (getvar "cmdactive") 1 )
(repeat (length lst)
(command (nth x lst))
(setq x (+ x 1))
)
)
)

BIGAL 发表于 2022-7-5 19:11:40

不用担心,检查您不需要(命令“”)来结束pline。
页: [1]
查看完整版本: 凸包