明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1546|回复: 2

求助:怎么求两条相交多段线的交点?

[复制链接]
发表于 2008-6-12 22:55:00 | 显示全部楼层 |阅读模式
怎么求两条相交多段线的交点?谢谢!
发表于 2008-6-13 08:23:00 | 显示全部楼层

请看VBA帮助中的IntersectWith方法。

语法如下:

Signature

RetVal = object.IntersectWith(IntersectObject, ExtendOption)

Object

MSITStore:C:\Program%20Files\Common%20Files\Autodesk%20Shared\ACADAUTO.CHM::/all_drawing_objects.htm">All Drawing Objects (Except Pviewport and PolygonMesh)
The object or objects this method applies to.

IntersectObject

Object, input-only;
The object can be one of MSITStore:C:\Program%20Files\Common%20Files\Autodesk%20Shared\ACADAUTO.CHM::/all_drawing_objects.htm">All Drawing Objects.

ExtendOption

AcExtendOption enum; input-only
This option specifies if none, one or both, of the objects are to be extended in order to attempt an intersection.

acExtendNone

Does not extend either object.

acExtendThisEntity

Extends the base object.

acExtendOtherEntity

Extends the object passed as an argument.

acExtendBoth

Extends both objects.

RetVal   这就是获取的交点坐标

Variant (array of doubles)
The array of points where one object intersects another object in the drawing

如VBA自带的例子:

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
发表于 2008-6-13 08:24:00 | 显示全部楼层

请查看VBA中的IntersectWith方法。

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

本版积分规则

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

GMT+8, 2024-11-26 09:35 , Processed in 0.154240 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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