Recently looked at some tolerance stuffs in AutoCAD .NET and noticed a pretty interesting thing. That is, sometimes two totally opposite vectors such as positive direction along the X axis and negative direction along the same X axis can be equal!
Here is the code to prove it.
[CommandMethod("VectorEqualTest")]
public static void VectorEqualTest_Method()
{
Editor ed = MgdAcApplication.DocumentManager.MdiActiveDocument.Editor;
try
{
Vector3d vec1 = new Vector3d(4e-13, 0, 0);
Vector3d vec2 = new Vector3d(-4e-13, 0, 0);
ed.WriteMessage("Is {0} equal to {1}? {2}", vec1, vec2, vec1.IsEqualTo(vec2));
}
catch (System.Exception ex)
{
ed.WriteMessage(ex.ToString());
}
}
Here is the output.
Command: VectorEqualTest
Is (4E-13,0,0) equal to (-4E-13,0,0)? True
So, it seems AutoCAD treats vectors pretty the same as points except for using a tighter tolerance (1e-12). It does not take the direction into consideration as far as vector equality is concerned. Pretty interesting, isn’t it?
By the way, the same applies to the 2d Vector too.
Though the chance is very slight, it may happen if we don’t normalize the vectors which only indicate directions or normals. Therefore, it’s always a good idea to normalize a vector of normal or direction kind instead of offset like before using it in any calculations or comparisons.
The leading edge AutoCAD .NET Addin Wizard (AcadNetAddinWizard) provides project wizards in C#, VB.NET and CLI/Managed C++, and various item wizards such as Event Handlers, Command/LispFunction Definers, and Entity/Draw Jiggers in both C# and VB.NET, to help program AutoCAD addins.
Posted by: |