明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1667|回复: 1

如何用vba来判断两直线是否相交?

[复制链接]
发表于 2004-6-19 10:22 | 显示全部楼层 |阅读模式
如何用vba来判断两直线是否相交,若相交,得出交点坐标,


我是新手,望各位前辈多多指教,谢谢!


MAIL:gujian@sohbicn.com
发表于 2004-6-19 13:53 | 显示全部楼层
使用直线对象的IntersectWith方法,参看帮助。
  1. Sub Example_IntersectWith()
  2.        ' This example creates a line and circle and finds the points at
  3.        ' which they intersect.
  4.       
  5.        ' Create the line
  6.        Dim lineObj As AcadLine
  7.        Dim startPt(0 To 2) As Double
  8.        Dim endPt(0 To 2) As Double
  9.        startPt(0) = 1: startPt(1) = 1: startPt(2) = 0
  10.        endPt(0) = 5: endPt(1) = 5: endPt(2) = 0
  11.        Set lineObj = ThisDrawing.ModelSpace.AddLine(startPt, endPt)
  12.                
  13.        ' Create the circle
  14.        Dim circleObj As AcadCircle
  15.        Dim centerPt(0 To 2) As Double
  16.        Dim radius As Double
  17.        centerPt(0) = 3: centerPt(1) = 3: centerPt(2) = 0
  18.        radius = 1
  19.        Set circleObj = ThisDrawing.ModelSpace.AddCircle(centerPt, radius)
  20.        ZoomAll
  21.            
  22.        ' Find the intersection points between the line and the circle
  23.        Dim intPoints As Variant
  24.        intPoints = lineObj.IntersectWith(circleObj, acExtendNone)
  25.       
  26.        ' Print all the intersection points
  27.        Dim I As Integer, j As Integer, k As Integer
  28.        Dim str As String
  29.        If VarType(intPoints) <> vbEmpty Then
  30.                For I = LBound(intPoints) To UBound(intPoints)
  31.                        str = "Intersection Point[" & k & "] is: " & intPoints(j) & "," & intPoints(j + 1) & "," & intPoints(j + 2)
  32.                        MsgBox str, , "IntersectWith Example"
  33.                        str = ""
  34.                        I = I + 2
  35.                        j = j + 3
  36.                        k = k + 1
  37.                Next
  38.        End If
  39. End Sub
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-21 17:05 , Processed in 0.565914 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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