MastroLube 发表于 2022-7-5 19:56:47

确定a的内部点

大家好,
 
我有两个小问题。
 
可以识别哪些坐标点是内部的,哪些是外部的吗?
 

 
不幸的是(角度……)只给出正数。
 
这是我使用的lisp代码:
(setq ent (vlax-ename->vla-object (car (entsel))))

(setq coordinate (vlax-safearray->list (vlax-variant-value (vlax-get-property ent 'Coordinates))))

(setq n_punti (/ (length coordinate) 2))

(setq indice 0)


(while (/= (1- indice) n_punti)

(setq punto_ins_A (list (nth (* 2 indice) coordinate) (nth (+ (* 2 indice) 1) coordinate)))
   
   (IF (= (1+ indice) n_punti)
   (progn
       (setq punto_ins_B (list (nth 0 coordinate) (nth 1 coordinate)))
       (setq punto_ins_C (list (nth 2 coordinate) (nth 3 coordinate)))
   )
   (Progn
       (setq punto_ins_B (list (nth (* 2 (1+ indice)) coordinate) (nth (+ (* 2 (1+ indice)) 1) coordinate)))
       (setq punto_ins_C (list (nth (* 2 (+ 2 indice)) coordinate) (nth (+ (* 2 (+ 2 indice)) 1) coordinate)))
   )
   )

...
)
 
另一个小问题是,是否可能知道如何创建多段线(顺时针或逆时针)
 
谢谢,丹尼斯

Lee Mac 发表于 2022-7-5 20:10:10

脑海中浮现出两种方式:
 
[列表]
[*]计算多段线顶点的凸包,并检索不在凸包上的顶点。
[/列表]
 
[列表]
[*]确定多段线是否为顺时针/逆时针方向(可能使用我的列表顺时针-p函数),然后检索沿相反方向的顶点(使用带有问题顶点和两个周围顶点的顺时针-p函数)。
[/列表]

MastroLube 发表于 2022-7-5 20:15:51

你好,李,谢谢你的快速回复
 
我已经做了一些例行工作来完成第一个请求,但我发现了一个小错误。
 

 
 
当然,黄点是内部的,但它不适用于我的应用程序。
我正在混凝土板中绘制路缘(找不到正确的英文单词,抱歉)。
 
有没有办法确定这一点?
 
这是我的代码:

....
(setq ent (vlax-ename->vla-object (car (entsel))))

(setq coordinate (vlax-safearray->list (vlax-variant-value (vlax-get-property ent 'Coordinates))))
;(command-s "_erase" (entlast) "")
;(vlax-invoke-method ent 'delete)
         

(setq n_punti (/ (length coordinate) 2))


;creazione lista punti e individuazione punti interni
(while (/= indice n_punti)
(setq punto_ins (list (nth (* 2 indice) coordinate) (nth (+ (* 2 indice) 1) coordinate)))
(setq lista_punti (cons punto_ins lista_punti))
(setq indice (1+ indice))
)
(setq punti_esterni (LM:ConvexHull lista_punti)) ;THANKS!!!


(setq indice 0)
(WHILE (/= indice n_punti)
   (IF (= (member (NTH indice lista_punti) punti_esterni) nil)
   (SETQ punti_interni (CONS (NTH indice lista_punti) punti_interni))
   )
   (SETQ indice (1+ indice))
)

;inserimento cordoli
(setq indice 0 indice_2 0)
(WHILE (/= indice n_punti)
   
   (IF (= indice_2 (- n_punti 1))
   (setq indice_2 0)
   (setq indice_2 (1+ indice))
   )

(VL-CMDF "_.-insert" nome_blocco (nth indice lista_punti) "" "" (* 180 (/ (angle (nth indice lista_punti) (nth indice_2 lista_punti)) pi)))
   (setq ent (vlax-ename->vla-object (entlast)))
   (COND ((and (= (member (NTH indice lista_punti) punti_interni) nil) (= (member (NTH indice_2 lista_punti) punti_interni) nil)) ;MODEL 1
                   (putdynpropvalue ent "lunghezza1" (- (distance (nth indice lista_punti) (nth indice_2 lista_punti)) (* dist_bordo 2)))
          )
         
              ((and (/= (member (NTH indice lista_punti) punti_interni) nil) (= (member (NTH indice_2 lista_punti) punti_interni) nil)) ;MODEL 2
               (putdynpropvalue ent "lunghezza1" (- (distance (nth indice lista_punti) (nth indice_2 lista_punti)) (* dist_bordo 2)))
                   (putdynpropvalue ent "lunghezza2" (+ (distance (nth indice lista_punti) (nth indice_2 lista_punti)) estensione larghezza))
          )
         ((and (= (member (NTH indice lista_punti) punti_interni) nil) (/= (member (NTH indice_2 lista_punti) punti_interni) nil)) ;MODEL 3
                   (putdynpropvalue ent "lunghezza1" (+ (distance (nth indice lista_punti) (nth indice_2 lista_punti)) estensione larghezza))
          )
         ((and (/= (member (NTH indice lista_punti) punti_interni) nil) (/= (member (NTH indice_2 lista_punti) punti_interni) nil)) ;MODEL 4
               (putdynpropvalue ent "lunghezza1" (+ (distance (nth indice lista_punti) (nth indice_2 lista_punti)) larghezza estensione))
               (command "rigen")
               (putdynpropvalue ent "lunghezza2" (+ (distance (nth indice lista_punti) (nth indice_2 lista_punti)) (* 2(+ dist_bordo larghezza estensione))))
               
                  
               
          )
         )

   (putdynpropvalue ent "larghezza" larghezza)
   (inserisci_attr nome_cordolo)
   (SETQ indice (1+ indice))
   )

...
 
谢谢,丹尼斯
 
(完成后,我将处理第二个请求)
 
编辑:我现在试试第二种方法,也许这是避免这个问题的唯一方法。:/

MastroLube 发表于 2022-7-5 20:25:30

这是固定的!
 
;;;(setq punti_esterni (LM:ConvexHull lista_punti))
(setq indice 0)
(while (/= (+ indice 2) n_punti)
(IF (= (gc:clockwise-p (nth indice lista_punti) (nth (+ indice 1) lista_punti) (nth (+ indice 2) lista_punti)) nil)
   (SETQ punti_interni (CONS (nth (+ indice 1) lista_punti) punti_interni))
   )
(SETQ indice (1+ indice))
)
(IF (= (gc:clockwise-p (nth indice lista_punti) (nth (+ indice 1) lista_punti) (nth 0 lista_punti)) nil)
   (SETQ punti_interni (CONS (nth (+ indice 1) lista_punti) punti_interni))
   )
(IF (= (gc:clockwise-p (nth (+ indice 1) lista_punti) (nth 0 lista_punti) (nth 1 lista_punti)) nil)
   (SETQ punti_interni (CONS (nth 0 lista_punti) punti_interni))
   )

;;;(setq indice 0)
;;;(WHILE (/= indice n_punti)
;;;    (IF (= (member (NTH indice lista_punti) punti_esterni) nil)
;;;      (SETQ punti_interni (CONS (NTH indice lista_punti) punti_interni))
;;;    )
;;;    (SETQ indice (1+ indice))
;;;)

marko_ribar 发表于 2022-7-5 20:36:37

MastroLube,请尝试以下代码:
 

(defun c:highlightinsidepts ( / LM:Clockwise-p ListClockwise-p lw pts ptss highlptsl sspts )

;; Clockwise-p-Lee Mac
;; Returns T if p1,p2,p3 are clockwise oriented or collinear

(defun LM:Clockwise-p ( p1 p2 p3 )
   (<(-(* (- (carp2) (carp1)) (- (cadr p3) (cadr p1)))
             (* (- (cadr p2) (cadr p1)) (- (carp3) (carp1)))
         )
         1e-8
   )
)

;;;ListClockwise-p
(defun ListClockwise-p ( lst / z vlst )
   (vl-catch-all-apply 'minusp
   (list
       (if
         (not
         (equal 0.0
             (setq z
               (apply '+
               (mapcar
                   (function
                     (lambda ( u v )
                     (- (* (caru) (cadrv)) (* (carv) (cadru)))
                     )
                   )
                   (setq vlst
                     (mapcar
                     (function
                         (lambda ( a b ) (mapcar '- b a))
                     )
                     (mapcar (function (lambda ( x ) (car lst))) lst)
                     (cdr (reverse (cons (car lst) (reverse lst))))
                     )
                   )
                   (cdr (reverse (cons (car vlst) (reverse vlst))))
               )
               )
             ) 1e-6
         )
         )
         z
         (progn
         (prompt "\n\nChecked vectors are colinear - unable to determine clockwise-p of list")
         nil
         )
       )
   )
   )
)

(setq lw (car (entsel "\nPick closed LWPOLYLINE...")))
(while (not (eq 1 (logand (cdr (assoc 70 (entget lw))) 1)))
   (prompt "\nPicked LWPOLYLINE isn't closed...")
   (setq lw (car (entsel "\nPick closed LWPOLYLINE...")))
)
(setq pts (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= (car x) 10)) (entget lw))))
(if (equal (car pts) (last pts) 1e-
   (setq pts (reverse (cdr (reverse pts))))
)
(if (Listclockwise-p pts) (setq pts (reverse pts)))
(setq highlptsl (mapcar '(lambda ( a b c ) (if (LM:Clockwise-p a b c) b)) pts (setq ptss (cdr (reverse (cons (car pts) (reverse pts))))) (cdr (reverse (cons (car ptss) (reverse ptss)))) ))
(setq highlptsl (vl-remove nil highlptsl))
(setq sspts (ssadd))
(foreach pt highlptsl
   (ssadd
   (entmakex (list '(0 . "POINT") '(62 . 1) (cons 10 pt)))
   sspts
   )
)
(sssetfirst nil sspts)
(prompt "\nHIT DEL KEY TO REMOVE HIGHLIGHTED POINTS")
(princ)
)
HTH,M.R。

Lee Mac 发表于 2022-7-5 20:47:37

我建议使用以下功能:
(defungetinternalpoints(lst)(if(LM:list顺时针-p lst)(setqlst(reverselst))(apply'append(mapcar(lambda(a b c)(if(LM:顺时针-p a b c)(listb)))(cons(lastlst)lst(append(cdrlst)(list(carlst))));;顺时针列出-p-Lee Mac;;如果点列表是顺时针方向的(defunLM:list顺时针-p(lst)(minusp(apply、+(mapcar(函数(lambda)-(*(carb)(cadra)(cara)(cadrb)))lst(cons(lastlst]))));;顺时针-p-Lee Mac;;如果p1、p2、p3为顺时针方向(defunLM:顺时针-p(p1 p2 p3)(

MastroLube 发表于 2022-7-5 20:49:24

谢谢你们,你们太棒了!

Lee Mac 发表于 2022-7-5 21:00:59

不客气!
页: [1]
查看完整版本: 确定a的内部点