明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2861|回复: 5

[几何] Tolerance容差类在点或向量比较时的应用示例

[复制链接]
发表于 2010-4-18 11:26 | 显示全部楼层 |阅读模式
  1.         [CommandMethod("tt")]
  2.         public static void Test()
  3.         {
  4.             var db = HostApplicationServices.WorkingDatabase;
  5.             var doc = Application.DocumentManager.GetDocument(db);
  6.             var ed = doc.Editor;
  7.             Point3d pt1 = new Point3d(0, 0.0001, 0);
  8.             Point3d pt2 = new Point3d(0, 0, 0);
  9.             ed.WriteMessage(
  10.                 "\nEqualPoint:{0}\nEqualVector:{1}",
  11.                 Tolerance.Global.EqualPoint,
  12.                 Tolerance.Global.EqualVector);
  13.             ed.WriteMessage("\npt1 == pt2 is {0}", pt1 == pt2);
  14.             Tolerance oldtol = Tolerance.Global;
  15.             Tolerance.Global = new Tolerance(0.01, 0.01);
  16.             ed.WriteMessage(
  17.                 "\nEqualPoint:{0}\nEqualVector:{1}",
  18.                 Tolerance.Global.EqualPoint,
  19.                 Tolerance.Global.EqualVector);
  20.             ed.WriteMessage("\npt1 == pt2 is {0}", pt1 == pt2);
  21.             Tolerance.Global = oldtol;
  22.         }
复制代码
运行结果
  1. 命令: tt
  2. EqualPoint:1E-10
  3. EqualVector:1E-12
  4. pt1 == pt2 is False
  5. EqualPoint:0.01
  6. EqualVector:0.01
  7. pt1 == pt2 is True
复制代码

评分

参与人数 1明经币 +2 收起 理由
mccad + 2 精品文章

查看全部评分

 楼主| 发表于 2010-4-18 11:27 | 显示全部楼层

点或向量在比较时,应用到了容差类的两个数值,实际使用时不需要重写这方面的方法

只需设置容差,然后直接判断就OK了

帮助文档中的相关内容

This is an instantiable class that is by default initialized to the default tolerances. Subsequently, the tolerances within it can be customized to suit a specific need. For example, an instance of this class may be specialized for use during surface intersection. 

Class Tolerance keeps two properties, EqualPoint and EqualVector, which are used in evaluation according to the following rules: 

  1. Two points, p1 and p2, are equal if

(p1 - p2).length() <= equalPoint

  1. Two vectors, v1 and v2, are equal if

(v1 - v2).length() <= equalVector

  1. Two vectors, v1 and v2, are parallel if

(v1/v1.length() - v2/v2.length() ).length() < equalVector

OR

(v1/v1.length() + v2/v2.length() ).length() < equalVector

  1. Two vectors, v1 and v2, are perpendicular if

abs((v1.dotProduct(v2))/(v1.length()*v2.length())) <= equalVector

  1. Two lines or rays are parallel (perpendicular) if their directional vectors are parallel (perpendicular)

发表于 2010-4-18 14:53 | 显示全部楼层

收到

发表于 2010-12-25 10:18 | 显示全部楼层
Point3d pt1 = new Point3d(0, 0.0001, 0);
            Point3d pt2 = new Point3d(0, 0, 0);
            ed.WriteMessage(
                "\nEqualPoint:{0}\nEqualVector:{1}",
                Tolerance.Global.EqualPoint,
                Tolerance.Global.EqualVector);
这一句话还不是很明白, Tolerance.Global.EqualPoint,Tolerance.Global.EqualVector 的作用最不清楚。
发表于 2010-12-25 10:58 | 显示全部楼层
谢谢!!学习了...
发表于 2010-12-25 11:55 | 显示全部楼层
原来有个Tolerance.Global并可写的,之前不知道,学习了,谢谢斑竹!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-9 12:20 , Processed in 1.253358 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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