明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1918|回复: 3

线的交点问题

[复制链接]
发表于 2006-2-27 17:26:00 | 显示全部楼层 |阅读模式

思路:选一条多段线,程序自动创建5条线,求交点

问题:所求交点重合为一个点???请高手指点。谢谢。

     Dim ent As AcadEntity

   On Error Resume Next
    N = -1
    Do
        ThisDrawing.Utility.GetEntity ent, Pnt, "选择区域范围线(多段线):"
        If Err Then Exit Sub
        If TypeName(ent) Like "IAcad*Polyline" Then Exit Do

    Loop
    Dim StartPt(0 To 2) As Double, EndPt(0 To 2) As Double

    For u = 1 To 5
   
        StartPt(0) = 100 + (u - 1) * 5
        StartPt(1) = 100
        StartPt(2) = 0
       
        EndPt(0) =120 + (u - 1) * 5
        EndPt(1) = 120

        EndPt(2) = 0
       
    Dim LineObj As AcadLine
   
    Set LineObj = ThisDrawing.ModelSpace.AddLine(StartPt, EndPt)
    LineObj.Update
    
   
    intPoints = LineObj.IntersectWith(ent, acExtendThisEntity)
    
      Dim str As String
    Dim pointObj As AcadPoint         '声明点的对象变量
    Dim Location(0 To 2) As Double    '声明点的位置数组变量
    
    
    If VarType(intPoints) <> vbEmpty Then
        For i = LBound(intPoints) To UBound(intPoints)
            str = "Intersection Point[" & k & "] is: " & Format(intPoints(j), "0.000") & "," & Format(intPoints(j + 1), "0.000") & "," & intPoints(j + 2)
            'MsgBox str, , "IntersectWith Example"
           
            Location(0) = Format(intPoints(j), "0.000")
            Location(1) = Format(intPoints(j + 1), "0.000")
            Location(2) = 0
           
            Set pointObj = ThisDrawing.ModelSpace.AddPoint(Location)
            str = ""
            i = i + 2
            j = j + 3
            k = k + 1
        Next i
    End If
   
    Next u

 楼主| 发表于 2006-2-28 15:37:00 | 显示全部楼层
没有人回答呀
发表于 2006-2-28 17:33:00 | 显示全部楼层
  1. If VarType(intPoints) <> vbEmpty Then
  2.         For i = LBound(intPoints) To UBound(intPoints)
  3.             str = "Intersection Point[" & k & "] is: " & Format(intPoints(j), "0.000") & "," & Format(intPoints(j + 1), "0.000") & "," & intPoints(j + 2)
  4.             'MsgBox str, , "IntersectWith Example"
  5.             
  6.             Location(0) = Format(intPoints(j), "0.000")
  7.             Location(1) = Format(intPoints(j + 1), "0.000")
  8.             Location(2) = 0
  9.             
  10.             Set pointObj = ThisDrawing.ModelSpace.AddPoint(Location)
  11.             str = ""
  12.             i = i + 2
  13.             j = j + 3
  14.             k = k + 1
  15.         Next i
  16.     End If
复制代码
for each 语句的种子是i,为什么在循环体还要改变它的值?
  1. Sub test2()
  2. Dim ent As AcadEntity
  3.    On Error Resume Next
  4.     n = -1
  5.     Do
  6.         ThisDrawing.Utility.GetEntity ent, pnt, "选择区域范围线(多段线):"
  7.         If Err Then Exit Sub
  8.         If TypeName(ent) Like "IAcad*Polyline" Then Exit Do
  9.     Loop
  10.     Dim StartPt(0 To 2) As Double, EndPt(0 To 2) As Double
  11.     For u = 1 To 5
  12.    
  13.         StartPt(0) = 100 + (u - 1) * 5
  14.         StartPt(1) = 100
  15.         StartPt(2) = 0
  16.         
  17.         EndPt(0) = 120 + (u - 1) * 5
  18.         EndPt(1) = 120
  19.         EndPt(2) = 0
  20.         
  21.     Dim LineObj As AcadLine
  22.    
  23.     Set LineObj = ThisDrawing.ModelSpace.AddLine(StartPt, EndPt)
  24.     LineObj.Update
  25.    
  26.    
  27.     intPoints = LineObj.IntersectWith(ent, acExtendThisEntity)
  28.    
  29.       Dim str As String
  30.     Dim pointObj As AcadPoint         '声明点的对象变量
  31.     Dim Location(0 To 2) As Double    '声明点的位置数组变量
  32.    
  33.    
  34.     If UBound(intPoints) > 0 Then
  35.         For i = 0 To UBound(intPoints) Step 3
  36.             j = i / 2
  37.             str = "Intersection Point[" & j & "] is: " & Format(intPoints(i), "0.000") & "," & Format(intPoints(i + 1), "0.000") & "," & intPoints(i + 2)
  38.             MsgBox str, , "IntersectWith Example"
  39.             
  40.             Location(0) = Format(intPoints(i), "0.000")
  41.             Location(1) = Format(intPoints(i + 1), "0.000")
  42.             Location(2) = Format(intPoints(i + 2), "0.000")
  43.             
  44.             Set pointObj = ThisDrawing.ModelSpace.AddPoint(Location)
  45.             str = ""
  46.         Next i
  47.     End If
  48.    
  49.     Next u
  50. End Sub
 楼主| 发表于 2006-3-1 13:49:00 | 显示全部楼层

i重给定值是因为没有加步长,默认为1,为得到正确坐标,需重赋值。

现在解决了,谢谢版主。

 

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

本版积分规则

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

GMT+8, 2024-11-27 06:30 , Processed in 0.171550 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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