CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ActiveX 开发指南

相关分类

相交方法 (ActiveX)

2023-1-4 05:53| 发布者: admin| 查看: 596| 评论: 0|来自: AutoCAD

摘要: 获取图形中一个对象与另一个对象相交的点。

获取图形中一个对象与另一个对象相交的点。

支持的平台:仅窗口

签名

工 务 局:

RetVal = object.IntersectWith(IntersectObject, ExtendOption)
对象

类型:所有图形对象(除外),属性引用PViewportPolygonMesh

此方法适用的对象。

相交对象

访问:仅输入

类型:对象

该对象可以是受支持的图形对象之一,也可以是 .AttributeReference

扩展选项

访问:仅输入

类型:枚举AcExtendOption

此选项指定是否不扩展一个对象或两个对象以尝试交集。

  • acExtendNone:不扩展任一对象。
  • acExtendThisEntity:扩展基本对象。
  • acExtendOtherEntity:扩展作为参数传递的对象。
  • acExtendBoth:扩展两个对象。

返回值(RetVal)

类型:变体(双打数组)

图形中一个对象与另一个对象相交的点数组。

言论

如果两个对象不相交,则不返回任何数据。您可以请求在一个或两个对象扩展以满足另一个对象时将发生的交点。例如,在下图中,Line1 是从中调用此方法的基对象,line3 是作为参数传递的对象。如果传递的ExtendOption是,则在扩展第 1 行时,将返回点 A 作为行 1 与行 3 相交的点。如果ExtendOption为 ,则不返回任何数据,因为即使扩展了第 3 行,它也不会与第 1 行相交。acExtendThisEntityacExtendOtherEntity

如果交集类型 isand line2 作为参数实体传递,则返回点 B。如果ExtendOption是 line2 是参数实体,则不返回任何数据。acExtendBothEntitiesacExtendNone



例子

工 务 局:

Sub Example_IntersectWith()
    ' This example creates a line and circle and finds the points at
    ' which they intersect.
    
    ' Create the line
    Dim lineObj As AcadLine
    Dim startPt(0 To 2) As Double
    Dim endPt(0 To 2) As Double
    startPt(0) = 1: startPt(1) = 1: startPt(2) = 0
    endPt(0) = 5: endPt(1) = 5: endPt(2) = 0
    Set lineObj = ThisDrawing.ModelSpace.AddLine(startPt, endPt)
        
    ' Create the circle
    Dim circleObj As AcadCircle
    Dim centerPt(0 To 2) As Double
    Dim radius As Double
    centerPt(0) = 3: centerPt(1) = 3: centerPt(2) = 0
    radius = 1
    Set circleObj = ThisDrawing.ModelSpace.AddCircle(centerPt, radius)
    ZoomAll
      
    ' Find the intersection points between the line and the circle
    Dim intPoints As Variant
    intPoints = lineObj.IntersectWith(circleObj, acExtendNone)
    
    ' Print all the intersection points
    Dim I As Integer, j As Integer, k As Integer
    Dim str As String
    If VarType(intPoints) <> vbEmpty Then
        For I = LBound(intPoints) To UBound(intPoints)
            str = "Intersection Point[" & k & "] is: " & intPoints(j) & "," & intPoints(j + 1) & "," & intPoints(j + 2)
            MsgBox str, , "IntersectWith Example"
            str = ""
            I = I + 2
            j = j + 3
            k = k + 1
        Next
    End If
End Sub

Visual LISP:

(vl-load-com)
(defun c:Example_IntersectWith()
    ;; This example creates a line and circle and finds the points at
    ;; which they intersect.
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))

    ;; Create the line
    (setq startPt (vlax-3d-point 1 1 0)
          endPt (vlax-3d-point 5 5 0))  

    (setq modelSpace (vla-get-ModelSpace doc))  
    (setq lineObj (vla-AddLine modelSpace startPt endPt))
        
    ;; Create the circle
    (setq centerPt (vlax-3d-point 1 1 0)
          radius 1)
    (setq circleObj (vla-AddCircle modelSpace centerPt radius))
    (vla-ZoomAll acadObj)
      
    ;; Find the intersection points between the line and the circle
    (setq intPoints (vla-IntersectWith lineObj circleObj acExtendNone))
    
    ;; Print all the intersection points
    (setq I 0
          j 0
          k 0)
    (if (/= (type intPoints) vlax-vbEmpty)
        (while (>= (vlax-safearray-get-u-bound (vlax-variant-value intPoints) 1) I)
            (setq tempPoint (vlax-safearray->list (vlax-variant-value intPoints)))
            (setq str (strcat "Intersection Point[" (itoa k) "] is: " (rtos (nth j tempPoint) 2) ","
                                                                      (rtos (nth (1+ j) tempPoint) 2) ","
                                                                      (rtos (nth (+ j 2) tempPoint) 2)))
            (alert str)
            (setq str ""
                  I (+ I 2)
                  j (+ j 3)
                  k (1+ k))
        )
    )
)

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )

GMT+8, 2024-5-19 15:01

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部