明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1434|回复: 3

很多line的交点求出

[复制链接]
发表于 2003-12-18 09:17:00 | 显示全部楼层 |阅读模式
怎样,可以把很多line的交点,类似于网格状的很多直线的焦点求出,附值给变量?
谢谢。
"觉得好,就打赏"
还没有人打赏,支持一下
发表于 2003-12-18 09:24:00 | 显示全部楼层
本站有這樣的程序, 我找找看. 

找到了.你試試合不合你用吧.
;;;;                        求得所選的圖的所有交點
;;----------------------------------------------
;; CDNC5-02.LSP
;; Bill Kramer
;; Find all intersections between objects in
;; the selection set SS.
;; Process - Create drawing with intersecting lines and lwpolylines.
;;           Load function set
;;           Run command function INTLINES
;;           Intersections are marked with POINT objects on current layer
(defun C:INTLINES (/ SSL  ;length of SS
     PTS   ;returning list
     AOBJ1  ;Object 1
     AOBJ2  ;Object 2
     N1   ;Loop counter
     N2   ;Loop counter
     IPTS   ;intersects
     A N NN HOLDOSMODE
    )
  (vl-load-com)
  (command "_.UNDO" "_GROUP")
  (setq HOLDOSMODE (getvar "OSMODE"))
  (setvar "OSMODE" 0)
  (setq SS (ssget '((0 . "*LINE,ARC,CIRCLE,ELLIPSE"))))
  (setq N1  0    ;index for outer loop
SSL (sslength SS)
  )     ; Outer loop, first through second to last
  (while (< N1 (1- SSL))  ; Get object 1, convert to VLA object type
    (setq AOBJ1 (ssname SS N1)
   AOBJ1 (vlax-ename->vla-object AOBJ1)
   N2 (1+ N1)
    )     ;index for inner loop
;;; Inner loop, go through remaining objects
    (while (< N2 SSL)   ; Get object 2, convert to VLA object
      (setq AOBJ2 (ssname SS N2)
     AOBJ2 (vlax-ename->vla-object AOBJ2)
;;;Find intersections of Objects
     IPTS  (vla-intersectwith
      AOBJ1
      AOBJ2
      0
    )   ; variant result
     IPTS  (vlax-variant-value IPTS)
      )
;;;Variant array has values?
      (if (> (vlax-safearray-get-u-bound IPTS 1) 0)
(progn    ;array holds values, convert it
   (setq IPTS   ;to a list.
   (vlax-safearray->list IPTS)
   )
;;;Loop through list constructing points
   (while (> (length IPTS) 0)
     (setq PTS  (cons (list (car IPTS)
       (cadr IPTS)
       (caddr IPTS)
        )
        PTS
         )
    IPTS (cdddr IPTS)
     )
   )
)
      )
      (setq N2 (1+ N2))
    )     ;inner loop end
    (setq N1 (1+ N1))
  )     ;outer loop end
  (print PTS)
  (setvar "OSMODE" HOLDOSMODE)
  (command "_.UNDO" "_END")
  (princ)
)
发表于 2003-12-18 09:24:00 | 显示全部楼层
显示交点的数目,至于怎样将它的值传给变量,我想你应该能做到吧


  1. (defun GetInterPoint (ent1 ent2 / ax_ent_1 ax_ent_2 intpoints points i)
  2.   (setq ax_ent_1 (vlax-ename->vla-object ent1)
  3.         ax_ent_2 (vlax-ename->vla-object ent2)
  4.   )
  5.   (setq intpoints (vla-intersectwith ax_ent_1 ax_ent_2 acextendnone))
  6.   (setq intpoints (vlax-variant-value intpoints))
  7.   (setq i 0)
  8.   (if (> (vlax-safearray-get-u-bound intpoints 1) 0)
  9.     (repeat (/ (+ 1
  10.               (- (vlax-safearray-get-u-bound intpoints 1)
  11.                  (vlax-safearray-get-l-bound intpoints 1)
  12.               )
  13.            )
  14.            3
  15.         )
  16.       (setq points (append points (list (list
  17.                       (vlax-safearray-get-element intpoints i)
  18.                       (vlax-safearray-get-element intpoints (+ i 1))
  19.                       (vlax-safearray-get-element intpoints (+ i 2))
  20.                     )))
  21.       )
  22.       (setq i (+ 3 i))
  23.     )
  24.   )
  25.   points
  26. )

  27. (defun c:main( / ss n i j ent1 ent2 points)
  28.   (setq ss (ssget))
  29.   (if ss
  30.     (setq n (sslength ss))
  31.   )
  32.   (setq i 0 j 0)
  33.   (while (< i n)
  34.     (setq j (1+ i))
  35.     (setq ent1 (ssname ss i))
  36.     (while (< j n)
  37.       (setq ent2 (ssname ss j))
  38.       (setq points (append points (getinterpoint ent1 ent2)))
  39.       (setq j (1+ j))
  40.     )
  41.     (setq i (1+ i))
  42.   )
  43.   (Princ points)
  44.   (princ (strcat "\n共有交点" (itoa (length points)) "个"))
  45.   (princ)
  46. )

 楼主| 发表于 2003-12-18 09:28:00 | 显示全部楼层
万分感谢两位版主。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-27 10:41 , Processed in 0.174490 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表