明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1691|回复: 6

快被气晕了,这么两行代码有毛病么?

[复制链接]
发表于 2007-3-15 01:32:00 | 显示全部楼层 |阅读模式

一个判断已知圆是否与两条已知线同时相交的,

    dim Keym  as Boolean

    If ThisDrawing.ActiveSpace = acModelSpace Then
        Set acCircle = ThisDrawing.ModelSpace.AddCircle(Pnt1, rad)
    Else
        Set acCircle = ThisDrawing.PaperSpace.AddCircle(Pnt1, rad)
    End If
    tmpPnt = acCircle.IntersectWith(AcLine1, acExtendNone)
    If VarType(tmpPnt) <> vbEmpty Then
        tmpPnt = acCircle.IntersectWith(AcLine2, acExtendNone)
        If VarType(tmpPnt) <> vbEmpty Then Keym = True
    End If

Pnt1, rad已知的数,AcLine1,AcLine2是屏幕选择的,并且生成了个如下图的圆acCircle ,

  

怎么执行结果就是Keym就等于True?acLine1并不与acCircle 相交啊!

我把VarType(tmpPnt) <> vbNull And VarType(tmpPnt) <> vbError 都加上了还是不行,不知道怎么写了。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2007-3-15 05:32:00 | 显示全部楼层

判断交点的元素数量为0试试

发表于 2007-3-15 09:37:00 | 显示全部楼层

我以前发了个关于 "关于求直线垂足方法的讨论" 的帖子

其中有一段是关于找交点的,以下是其中的一段代码.

其中有一段是关于找交点的,以下是其中的一段代码.

...

returnPnt = lineObj.IntersectWith(objline, acExtendNone)
  If VarType(returnPnt) <> vbEmpty Then
     If LBound(returnPnt) <= UBound(returnPnt) Then
        pt(0) = returnPnt(0)
        pt(1) = returnPnt(1)
        pt(2) = returnPnt(2)
     End If
  End If

...

发表于 2007-3-15 09:55:00 | 显示全部楼层

在你的程序中

tmpPnt = acCircle.IntersectWith(AcLine1, acExtendNone)

执行后,不管有无交点变量 tmpPnt 都不再是 vbEmpty 了,所以其后面的判断语句总是true.

我开始也是用 If VarType(tmpPnt) <> vbEmpty Then 判断有无交点的,

我后来发现无交点时变量 tmpPnt 的下标大于上标, 也就是 tmpPnt 是个错误的变体.


发表于 2007-3-15 20:36:00 | 显示全部楼层

if ubound(tmpPnt)>0 then

如果无交点tmpPnt是上标为-1的数组(晕,比较郁闷)

发表于 2007-3-15 21:46:00 | 显示全部楼层
判断很简单,ubound(tmpPnt)>0 有交点,ubound(tmpPnt)=-1无交点!个人经验!
 楼主| 发表于 2007-3-15 23:38:00 | 显示全部楼层

哦,太谢谢各位了!

今天又重试了一下,用Variant变量的其中一个元素判断就好了

即 If VarType(tmpPnt(0)) <> vbEmpty Then 就正常了。

不过看样子还是ubound(tmpPnt)>0的方法才是正规的方法。

再次谢谢各位。

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

本版积分规则

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

GMT+8, 2025-2-22 18:37 , Processed in 0.229582 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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