雪山飞狐_lzh 发表于 2010-4-18 11:26:00

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

      
      public static void Test()
      {
            var db = HostApplicationServices.WorkingDatabase;
            var doc = Application.DocumentManager.GetDocument(db);
            var ed = doc.Editor;

            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);
            ed.WriteMessage("\npt1 == pt2 is {0}", pt1 == pt2);

            Tolerance oldtol = Tolerance.Global;
            Tolerance.Global = new Tolerance(0.01, 0.01);

            ed.WriteMessage(
                "\nEqualPoint:{0}\nEqualVector:{1}",
                Tolerance.Global.EqualPoint,
                Tolerance.Global.EqualVector);
            ed.WriteMessage("\npt1 == pt2 is {0}", pt1 == pt2);

            Tolerance.Global = oldtol;
      }运行结果
命令: tt

EqualPoint:1E-10
EqualVector:1E-12
pt1 == pt2 is False
EqualPoint:0.01
EqualVector:0.01
pt1 == pt2 is True

雪山飞狐_lzh 发表于 2010-4-18 11:27:00

<p>点或向量在比较时,应用到了容差类的两个数值,实际使用时不需要重写这方面的方法</p><p>只需设置容差,然后直接判断就OK了</p><p>帮助文档中的相关内容</p><p class="Element10">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.&nbsp;</p><p class="Element10"></p><p class="Element10">Class Tolerance keeps two properties, EqualPoint and EqualVector, which are used in evaluation according to the following rules:&nbsp;</p><p class="Element10"></p><ol class="Element630"><li class="Element600" value="1">Two points, p1 and p2, are equal if </li></ol><p>
        </p><p></p><div class="Element103"><div class="Element102"><pre class="Element102" style="FONT-FAMILY: Verdana,Arial,Helvetica,sans-serif;">(p1 - p2).length() &lt;= equalPoint</pre></div></div><p class="Element10"></p><ol class="Element630"><li class="Element600" value="2">Two vectors, v1 and v2, are equal if </li></ol><p></p><div class="Element103"><div class="Element102"><pre class="Element102" style="FONT-FAMILY: Verdana,Arial,Helvetica,sans-serif;">(v1 - v2).length() &lt;= equalVector</pre></div></div><p class="Element10"></p><ol class="Element630"><li class="Element600" value="3">Two vectors, v1 and v2, are parallel if </li></ol><p></p><div class="Element103"><div class="Element102"><pre class="Element102" style="FONT-FAMILY: Verdana,Arial,Helvetica,sans-serif;">(v1/v1.length() - v2/v2.length() ).length() &lt; equalVector</pre></div></div><p class="Element10">OR </p><div class="Element103"><div class="Element102"><pre class="Element102" style="FONT-FAMILY: Verdana,Arial,Helvetica,sans-serif;">(v1/v1.length() + v2/v2.length() ).length() &lt; equalVector</pre></div></div><p class="Element10"></p><ol class="Element630"><li class="Element600" value="4">Two vectors, v1 and v2, are perpendicular if </li></ol><p></p><div class="Element103"><div class="Element102"><pre class="Element102" style="FONT-FAMILY: Verdana,Arial,Helvetica,sans-serif;">abs((v1.dotProduct(v2))/(v1.length()*v2.length())) &lt;= equalVector</pre></div></div><p class="Element10"></p><ol class="Element630"><li class="Element600" value="5">Two lines or rays are parallel (perpendicular) if their directional vectors are parallel (perpendicular) </li></ol><p></p><a name="4E6F746573"></a><div class="Element14"></div>

游天居士 发表于 2010-4-18 14:53:00

<p>收到</p>

yxr_MJTD 发表于 2010-12-25 10:18:03

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 的作用最不清楚。

chpmould 发表于 2010-12-25 10:58:31

谢谢!!学习了...

sieben 发表于 2010-12-25 11:55:26

原来有个Tolerance.Global并可写的,之前不知道,学习了,谢谢斑竹!
页: [1]
查看完整版本: Tolerance容差类在点或向量比较时的应用示例