明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2980|回复: 5

简单的求直线斜率和截矩函数问题

[复制链接]
发表于 2011-12-5 17:31 | 显示全部楼层 |阅读模式
本帖最后由 syeanwoo 于 2011-12-5 17:34 编辑

在一个过程中调用了求直线斜率a和截矩b的函数(见最后),用一个二维点Point2d的X和Y分别来存储a和b,VS没有提示有问题,但是运行时却说4613行( 现在的第3行:Point3d pt1 = L3d.StartPoint;)有问题,以下为错误提示信息,望各位赐教,多谢:
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.InvalidOperationException: Operation is not valid due to the current state of the object.
   at Autodesk.AutoCAD.Geometry.Curve3d.get_StartPoint()
   at MyProject.CADCom.LineAB(Line3d L3d) in F:\Users\Syean Woo\Documents\Visual Studio 2010\Projects\MyFirstProject\MyFirstProject\MyClass.cs:line 4613
   at MyProject.CADCom.IntersectPoints(Line3d L1, Line3d L2) in F:\Users\Syean Woo\Documents\Visual Studio 2010\Projects\MyFirstProject\MyFirstProject\MyClass.cs:line 4581
   at MyProject.ModifyObjects.ThreeArcs() in F:\Users\Syean Woo\Documents\Visual Studio 2010\Projects\MyFirstProject\MyFirstProject\MyClass.cs:line 2741
   at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorker(MethodInfo mi, Object commandObject, Boolean bLispFunction)
   at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorkerWithExceptionFilter(MethodInfo mi, Object commandObject, Boolean bLispFunction)
   at Autodesk.AutoCAD.Runtime.CommandClass.CommandThunk.Invoke()

  1.         static public Point2d LineAB(Line3d L3d)
  2.         {
  3.             Point3d pt1 = L3d.StartPoint;
  4.             Point3d pt2 = L3d.EndPoint;
  5.             double a = (pt1.Y - pt2.Y) / (pt1.X - pt2.X);
  6.             double b = (pt1.X * pt2.Y - pt2.X * pt1.Y) / (pt1.X - pt2.X);
  7.             return new Point2d(a, b);
  8.         }
复制代码



发表于 2011-12-5 18:06 | 显示全部楼层
粗看上去好像是版本有问题。get_StartPoint  这个是老旧的格式。
 楼主| 发表于 2011-12-5 18:49 | 显示全部楼层
badboy518 发表于 2011-12-5 18:06
粗看上去好像是版本有问题。get_StartPoint  这个是老旧的格式。

你是说用在引用L3d.StartPoint时调用的get_StartPoint的版本问题?这个是AutoCAD封装好了的,我们怎么知道啊?我只知道我要引用它,而且只有这一个方法。
发表于 2011-12-5 22:31 | 显示全部楼层
应该是AutoCAD没补充好相应函数,或许以后也不会补充,Line3d表示的应该是无限长线(或说虚构的构造线)没有或说不提供StartPoint也是正常的,或说符合逻辑的.

1,你不应该这样子来计算Line3d的斜率,或许你应该使用其Direction属性
2,你的函数有Bug,函数里面的除数可能为0.
 楼主| 发表于 2011-12-6 09:13 | 显示全部楼层
sieben 发表于 2011-12-5 22:31
应该是AutoCAD没补充好相应函数,或许以后也不会补充,Line3d表示的应该是无限长线(或说虚构的构造线)没有或说 ...

非常感谢,Divided by Zero的Bug很容易解决。但是AutoCAD提供了StartPoint属性却不让我们访问吗?另外既然是无限长线就不应该用StartPoint和EndPoint属性了。
我还是用Line来解决吧!最后非常感谢sieben,非常感谢!
发表于 2011-12-6 10:41 | 显示全部楼层
Line3d 的StartPoint和EndPoint属性 来自其继承类,这是标配与专用的固有矛盾,正常得很.
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-8 04:21 , Processed in 0.203072 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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