Offsetting a Line

(A.Ai.) #1

I am trying to offset a polyline, so that the offsetted curve is within a predefined boundary.
Curiously, the code only works if the original polyline contains more than one segment (ie. is not a line).

What am I doing wrong here?
Thanks! :slight_smile:

private void RunScript(Polyline poly, double distance, Polyline Boundary, ref object A)
   Curve myCrv = new NurbsCurve(poly.ToNurbsCurve());

   Vector3d tangent = new Vector3d(myCrv.TangentAt(0.5)); //gets unit tangent
   bool rot = tangent.Rotate(1.5708, new Vector3d(0, 0, 1));
   Point3d testPt = new Point3d(myCrv.PointAt(0.5) + tangent * 0.05);
   if (!(IsInside(testPt, Boundary))) //IsInside tests if a point is within a polyline boundary
      tangent = tangent * (-1);

   //do offset
   Curve[] offsetCrv = myCrv.Offset(testPt, tangent, distance, 0.01, CurveOffsetCornerStyle.Sharp);
   A = offsetCrv;


(Lando Schumpich) #2

With “not working” you mean A==Null for a 2 point polyline?

I see a few things here:
-The vector for the offset function should be normal to the offset plane. Since you rotate your tangent on the xy plane shouldn’t you offset on it too?

  • are your polylines closed?

(A.Ai.) #3

Thanks Lando, I confused the WorldXY (offset plane) normal vector with the normal vector of my Curve within the WorldXY plane. Thanks for your help!