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[4][];
        for (int i = 0; i < 4; i++)
        {
            ptz[i] = new double[2];
            ptz[i][0] = plist[i].X;
            ptz[i][1] = plist[i].Y;
        }

        double[] dblcen = Misc.Centroid(ptz);
        Point3d cen = new Point3d(dblcen[0], dblcen[1], 0);
        PolylineCurve crv = new PolylineCurve(plist);
        Curve[] offsetcr = crv.Offset(cen, Vector3d.ZAxis, offsetdistance,0.1, CurveOffsetCornerStyle.None);
        PolylineCurve offsetpl = offsetcr[0].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

@Christoph1, please post the curve.

_
c.

@clement thanks for coming back. I actually only forgot to close the curve (i.e. plist). Adding the starting point plist.Add(plist[0]) 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[4][];
        for (int i = 0; i < 4; i++)
        {
            ptz[i] = new double[2];
            ptz[i][0] = plist[i].X;
            ptz[i][1] = plist[i].Y;
        }

        double[] dblcen = Misc.Centroid(ptz);
        Point3d cen = new Point3d(dblcen[0], dblcen[1], 0);
        
        plist.Add(plist[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[0].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