TheSwamp

Code Red => .NET => Topic started by: pjm8765 on May 08, 2019, 05:28:13 AM

Title: Are Line angles always positive?
Post by: pjm8765 on May 08, 2019, 05:28:13 AM
Don't get me wrong, it makes perfect sense to see the angles reported as positive values.  It's just that I look after other software which lands up with negative angles (calculated in the software, rather than the angles reported by AutoCAD) and I'm used to taking into account the (anti)clockwise direction.  It wouldn't be the first time this software I inherited had design decisions that don't make sense.

So, if I'm purely using the API to report line angles I can safely assume they will always be positive?
Title: Re: Are Line angles always positive?
Post by: gile on May 08, 2019, 06:01:39 AM
Hi,

From the tests I did, the Line.Angle property returns the angle in radians between the WCS X axis and the projection of the line on the WCS XY plane measured couter-clockwise in  Xthe range [0 .. 2*pi] (i.e. always positive).
You can test it by yourself.
Code - C#: [Select]
  1.         [CommandMethod("TEST")]
  2.         public static void Test()
  3.         {
  4.             var ed = Application.DocumentManager.MdiActiveDocument.Editor;
  5.             var peo = new PromptEntityOptions("\nSelect Line: ");
  6.             peo.SetRejectMessage("\nSelected object is not a Line.");
  7.             peo.AddAllowedClass(typeof(Line), true);
  8.             var per = ed.GetEntity(peo);
  9.             if (per.Status == PromptStatus.OK)
  10.             {
  11.                 using (var tr = new OpenCloseTransaction())
  12.                 {
  13.                     var line = (Line)tr.GetObject(per.ObjectId, OpenMode.ForRead);
  14.                     ed.WriteMessage($"\nAngle = {Converter.AngleToString(line.Angle)}");
  15.                 }
  16.             }
  17.         }
Title: Re: Are Line angles always positive?
Post by: pjm8765 on May 08, 2019, 06:28:19 AM
Thanks very, that's good to know.