明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
楼主: lusj

[求助]请问如何求出两条多义线的交点?

  [复制链接]
发表于 2006-1-16 14:36:00 | 显示全部楼层

谁能告诉我下面程序如何放到CAD程序中去及又如何使用?谢了(QQ:308302994)

 

 

(defun get_all_inters_in_SS (SS /
        SSL ;length of SS
        TS ;returning list
        aObj1 ;Object 1
        aObj2 ;Object 2
        N1  ;Loop counter
        N2  ;Loop counter
        iPts ;intersects
        )
  (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 ts (cons (list (car iPts)
      (cadr iPts)
      (caddr iPts))
       ts)
    iPts (cdddr iPts)))))
      (setq N2 (1+ N2))) ;inner loop end
    (setq N1 (1+ N1))) ;outer loop end
  ts) ;return list of points found
;;-----------------------------------------------   END LISTING 1
;;
;; Remaining lines of code for download version, used to demonstrate and test the utility in Listing 1.
;;
;; rocess - Create drawing with intersecting lines and lwpolylines.
;;           Load function set
;;           Run command function INTLINES
;;           Intersections are marked with OINT objects on current layer
;;
(defun C:INTLINES ()
  (prompt "\nINTLINES running to demonstrate GET_ALL_INTERS_IN_SS function.")
  (setq SS1 (get_all_lines_as_SS)
 TS (get_all_inters_in_ss SS1)
        )
  (foreach TS ;;Loop through list of points
    (command "_POINT" T)) ;;Create point object
  (setvar "PDMODE" 34) ;;display points so you can see them
  (command "_REGEN")
)
;;
;;-----------------------------------------------
;;  Get all lines and lwpolyline objects in the
;;  drawing and return as a selection set.
;;
(defun get_all_Lines_as_SS ()
  (ssget "X" '((0 . "LINE,LWPOLYLINE"))))
;;

发表于 2006-2-10 10:26:00 | 显示全部楼层

不会用啊  说清好吗

发表于 2006-2-17 07:45:00 | 显示全部楼层

现成的

dispbbs.asp?boardID=3&ID=8719&page=1

发错了位置,请版主删除。

发表于 2006-3-1 18:28:00 | 显示全部楼层

精彩,本菜鸟顶一个,各位高手太棒了。

发表于 2006-3-30 17:49:00 | 显示全部楼层
都用的 intersectwith方法,有些缺点,一是当一段圆弧极短的时候,会得出错误的交点,还有就是两条线靠得很近,但不相交,但可以求出交点,如果不信,我可以提供一个图试试
发表于 2006-6-26 12:35:00 | 显示全部楼层
这些交点程序,得到的结果都包含了线的顶点坐标,这样对于任意个多边形的相邻的情况(注意不是相交的)既有几个顶点的边重合的时候,这样得到的坐标不是交点的坐标,而是重合点的坐标!请问如何去除顶点坐标?
发表于 2006-7-23 20:39:00 | 显示全部楼层
如果只是在屏幕上读交点,那是很容易的,打开捕捉,设定为交点就行了,用得着这么兴师动众?
发表于 2006-7-26 00:01:00 | 显示全部楼层

我顶.顶,顶,顶.

发表于 2006-8-9 23:02:00 | 显示全部楼层
;求两实体交点
(defun c:get_int0( / ent1 ent2 ps)
  (setq ent1 (car (entsel "选择第一实体:")))
  (setq ent2 (car (entsel "选择第二实体:")))
  (print)
  (setq ps (obj_int ent1 ent2))
)
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;功能:返回两个对象的所有交点
;参数: ent1、ent2 均为ename对象
(defun obj_int (ent1 ent2 / ax_ent_1 ax_ent_2 intpoints points i)
   (setq ax_ent_1 (vlax-ename->vla-object ent1)
         ax_ent_2 (vlax-ename->vla-object ent2)
   )
   (setq intpoints (vla-intersectwith ax_ent_1 ax_ent_2 acextendnone))
   (setq intpoints (vlax-variant-value intpoints))
   (setq i 0)
   (if (> (vlax-safearray-get-u-bound intpoints 1) 0)
     (repeat (/ (+ 1
               (- (vlax-safearray-get-u-bound intpoints 1)
                  (vlax-safearray-get-l-bound intpoints 1)
               )
            )
            3
         )
       (setq points (append points (list (list
         (vlax-safearray-get-element intpoints i)
         (vlax-safearray-get-element intpoints (+ i 1))
         (vlax-safearray-get-element intpoints (+ i 2))
       )))
       )
       (setq i (+ 3 i))
     )
   )
   points
)
发表于 2006-8-20 18:09:00 | 显示全部楼层

长见识了,学习中…………

您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-4-30 03:50 , Processed in 0.168319 second(s), 20 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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