获取图形中一个对象与另一个对象相交的点。 支持的平台:仅窗口 签名工 务 局: RetVal = object.IntersectWith(IntersectObject, ExtendOption) 返回值(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))
)
)
)
|
|Archiver|CAD开发者社区
( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-10-29 08:51
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.