Author Topic: add length curve by calculate vector  (Read 1639 times)

0 Members and 1 Guest are viewing this topic.

daboho

  • Newt
  • Posts: 40
add length curve by calculate vector
« on: May 31, 2022, 05:28:41 AM »
i want to add length of curve (in startpoint and endpoint)
add from startpoint  = 0.2 m
add from endpoint = 0.2 m
i am confuse in red of code how to calculate vector
how to calculate this part code
Code: [Select]
var dist = vec1 * 0.2; // i am confuse in this code how to calculate vector to add 0.2 m
Code - C#: [Select]
  1.  [CommandMethod("xt")]
  2.         public void XtendMethod()
  3.  
  4.         {
  5.  
  6.             Document doc = Application.DocumentManager.MdiActiveDocument;
  7.             Editor ed = doc.Editor;
  8.             Database db = doc.Database;
  9.             try
  10.             {
  11.                 var pso = new PromptSelectionOptions();
  12.                 pso.MessageForAdding = "\nSelect Curve";
  13.                 var psr = ed.GetSelection(pso);
  14.                 if (psr.Status != PromptStatus.OK) return;
  15.                 using (Transaction tr= doc.TransactionManager.StartTransaction())
  16.                 {
  17.                     foreach (SelectedObject s in psr.Value)
  18.                     {
  19.                         Curve curve = tr.GetObject(s.ObjectId, OpenMode.ForWrite) as Curve;                
  20.                             var length = curve.GetDistanceAtParameter(1);
  21.                             var vec1 = (curve.EndPoint - curve.StartPoint).GetNormal();
  22.                             var dist = vec1 * 0.2; // i am confuse in this code how to calculate vector to add 0.2 m
  23.                             Point3d nEp = curve.GetPointAtParameter(1) + dist;
  24.                             Point3d nSp = curve.GetPointAtParameter(0) - dist;
  25.                             curve.Extend(true, nSp);
  26.                             curve.Extend(false, nEp);
  27.                     }
  28.                     tr.Commit();
  29.                 }
  30.             }
  31.             catch (System.Exception ex)
  32.             {
  33.                 ed.WriteMessage(ex.Message);
  34.             }
  35.  
  36.         }
  37.  
  38.  
« Last Edit: May 31, 2022, 06:21:58 PM by kdub »

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: add length curve by calculate vector
« Reply #1 on: May 31, 2022, 07:03:42 AM »
Hi,

This should work with any type of curve with a StartPoint and a EndPoint.
Code - C#: [Select]
  1. var startVector = curve.GetFirstDerivative(curve.StartPoint).Negate();
  2. var endVector = curve.GetFirstDerivative(curve.EndPoint);
Speaking English as a French Frog

daboho

  • Newt
  • Posts: 40
Re: add length curve by calculate vector
« Reply #2 on: June 22, 2022, 11:10:12 AM »
Sorri for late reply thank for your answer