title: Is There is a way in .net to get centroid for polyline?
body: <p>I want to get the centroid of polyline2d.  I have a polyline from TraceBoundary like so:</p>
  
  <pre><code>DBObjectCollection objs = Application.DocumentManager.MdiActiveDocument.Editor.TraceBoundary(Point, false);
  Polyline polyline = (Polyline)objs[0];
  Point2d centroid = ***The missing part i need any way to get center of gravity of the above polyline as point2d***
  </code></pre>
  
  <p>I was doing that before with autolisp:</p>
  
  <pre><code>(setq arob (entlast))
  (setq enpol (vlax-ename-&gt;vla-object arob))
  (setq cgpoint (vlax-get-property enpol 'Centroid))
  </code></pre>
  
  <p>I have a mathematical solution, but it's not valid when the polyline comes with some curves.</p>
  
  <p>I won't use this function:</p>
  
  <pre><code>public static Point2d GetPolyLineCentroid(Polyline polyline)
      {
          double area = polyline.Area;
          double cx = 0.0;
          double cy = 0.0;
          double X0 = 0.0;
          double Y0 = 0.0;
          double X1 = 0.0;
          double Y1 = 0.0;
  
          for (int i = 0; i &lt; polyline.NumberOfVertices - 1; i++)
          {
              X0 = polyline.GetPoint2dAt(i).X;
              Y0 = polyline.GetPoint2dAt(i).Y;
              X1 = polyline.GetPoint2dAt(i + 1).X;
              Y1 = polyline.GetPoint2dAt(i + 1).Y;
  
              cx += (X0 + X1) * (X0 * Y1 - X1 * Y0);
              cy += (Y0 + Y1) * (X0 * Y1 - X1 * Y0);
          }
  
          // last Point
          int Lv = polyline.NumberOfVertices - 1;
          X0 = polyline.GetPoint2dAt(Lv).X;
          Y0 = polyline.GetPoint2dAt(Lv).Y;
          X1 = polyline.GetPoint2dAt(0).X;
          Y1 = polyline.GetPoint2dAt(0).Y;
  
          cx += (X0 + X1) * (X0 * Y1 - X1 * Y0);
          cy += (Y0 + Y1) * (X0 * Y1 - X1 * Y0);
  
  
          cx /= 6 * area;
          cy /= 6 * area;
  
          return new Point2d(cx, cy);
      }
  </code></pre>
  
  <p>I don't want to use AutoLisp.  Is there a way to do this in .NET?</p>