HARRY-PLOTTER 发表于 2022-7-5 23:38:35

与点a p最近的顶点

如何找到距离多边形上选定点最近的顶点?谢谢

MSasu 发表于 2022-7-5 23:47:10

建立一个顶点列表和距离所说的点,并排序升序;保留第一个元素。

GP_ 发表于 2022-7-5 23:55:03

 
另一个:
 
(defun c:test ()
   (setq a (vlax-ename->vla-object (car (entsel "\nSelect Polyline"))))
   (setq b (vlax-curve-getClosestPointTo a (trans (cadr (grread T)) 1 0)))
   (setq c (vlax-curve-getParamAtPoint a b))
   (or (< (- c (setq c (fix c))) 0.50000000001) (setq c (1+ c)))
   (setq v (vlax-curve-getPointAtParam a c))
   (princ (strcat "\nVertex n. " (itoa (1+ c)) " (" (rtos (car v)) " " (rtos (cadr v)) ")" ))
   (princ)
)
   

HARRY-PLOTTER 发表于 2022-7-6 00:01:55

谢谢,太好了!

Tharwat 发表于 2022-7-6 00:06:11

无需使用vlax-***函数将对象转换为

Tharwat 发表于 2022-7-6 00:14:28

另一种方法是在最近的参数处添加绿点。
 

(defun c:Test (/ s e pr p pt a b)
;;    Tharwat 2014. cadtutor      ;;
(if (and (setq s (entsel)) (eq (cdr (assoc 0 (entget (setq e (car s))))) "LWPOLYLINE"))
   (progn (setq pr (vlax-curve-getparamatpoint (car s) (setq p (vlax-curve-getclosestpointto (car s) (cadr s)))))
          (if (< (distance p (setq a (vlax-curve-getpointatparam (car s) (fix pr))))
               (distance p (setq b (vlax-curve-getpointatparam (car s) (1+ (fix pr)))))
            )
            (setq pt a)
            (setq pt b)
          )
          (entmakex (list '(0 . "POINT") (cons 10 pt) '(62 . 3)))
   )
   (princ "\n Nothing selected or not a Polyline <!>")
)
(princ)
)
(vl-load-com)

GP_ 发表于 2022-7-6 00:18:32

 
不客气
 
 
 
哎呀

MSasu 发表于 2022-7-6 00:22:39

VLAX-CURVE-*函数族的参数类型在帮助中列出为
因此,即使支持实体名称,也要遵守良好的编程实践。如果有一天Autodesk决定强制执行该规则,这将确保代码正常运行(这在过去发生过,尽管我记不起该函数)。

Tharwat 发表于 2022-7-6 00:32:36

我认为Autodesk不再关心Autolisp的任何发展,因为他们正在强迫他们的马使用VB。网已经很长一段时间了。

Kowal 发表于 2022-7-6 00:34:36

如何获得多段线线段上最近和相反的点?
页: [1] 2
查看完整版本: 与点a p最近的顶点