 # Offset closed polygon to inside

Dear all,
I’m trying to offset a (convex) quadrilateral to the inside. But for some reasons, two of the four offset points are not where they should be, as can be seen in the image:

What am I missing?

Attached is also the script:

``````    internal static double[][] PtsFromOffsetRectangle(List<Point3d>plist, double offsetdistance)
{
double[][] ptz = new double[];
for (int i = 0; i < 4; i++)
{
ptz[i] = new double;
ptz[i] = plist[i].X;
ptz[i] = plist[i].Y;
}

double[] dblcen = Misc.Centroid(ptz);
Point3d cen = new Point3d(dblcen, dblcen, 0);
PolylineCurve crv = new PolylineCurve(plist);
Curve[] offsetcr = crv.Offset(cen, Vector3d.ZAxis, offsetdistance,0.1, CurveOffsetCornerStyle.None);
PolylineCurve offsetpl = offsetcr.ToPolyline(0, 0, 0,System.Double.MaxValue, 0, 0.01, 0, 0,true);
Point3d offsetpt0 = offsetpl.Point(0);
Point3d offsetpt1 = offsetpl.Point(1);
Point3d offsetpt2 = offsetpl.Point(2);
Point3d offsetpt3 = offsetpl.Point(3);

return new double[][] {
new double[] {offsetpt0.X, offsetpt0.Y },
new double[] {offsetpt1.X, offsetpt1.Y },
new double[] {offsetpt2.X, offsetpt2.Y},
new double[] {offsetpt3.X, offsetpt3.Y}};
}
``````

Many thanks,
Christoph

_
c.

@clement thanks for coming back. I actually only forgot to close the curve (i.e. plist). Adding the starting point plist.Add(plist) did the trick.

I also noticed, the crv.Offset function really doesn’t like zero tolerance.

Attached the working script:

``````    internal static double[][] PtsFromOffsetRectangle(List<Point3d>plist, double offsetdistance)
{

double[][] ptz = new double[];
for (int i = 0; i < 4; i++)
{
ptz[i] = new double;
ptz[i] = plist[i].X;
ptz[i] = plist[i].Y;
}

double[] dblcen = Misc.Centroid(ptz);
Point3d cen = new Point3d(dblcen, dblcen, 0);

PolylineCurve crv = new PolylineCurve(plist);
crv.MakeClosed(0.001);
Curve[] offsetcr = crv.Offset(cen, Vector3d.ZAxis, offsetdistance,0.001, CurveOffsetCornerStyle.None);
PolylineCurve offsetpl = offsetcr.ToPolyline(0, 0, 0,System.Double.MaxValue, 0, 0.001, 0, 0,true);
Point3d offsetpt0 = offsetpl.Point(0);
Point3d offsetpt1 = offsetpl.Point(1);
Point3d offsetpt2 = offsetpl.Point(2);
Point3d offsetpt3 = offsetpl.Point(3);

return new double[][] {
new double[] {offsetpt0.X, offsetpt0.Y },
new double[] {offsetpt1.X, offsetpt1.Y },
new double[] {offsetpt2.X, offsetpt2.Y},
new double[] {offsetpt3.X, offsetpt3.Y}};
}``````
1 Like