Curve.Offset returns null

I can’t figure out how to offset this curve using Rhino Common. When I offset it in Rhino, everything works fine, but curve.Offset fails.

This file contains the curve and the direction point used
offsetBug.3dm (47.9 KB)

My function call looks like:
curve.Offset(
directionPoint,
Vector3d.ZAxis,
6,
RhinoDoc.ActiveDoc.ModelAbsoluteTolerance,
CurveOffsetCorenerStyle.Sharp
);

I have tried dropping the tolerance, to no avail. If anyone has any ideas of what may be going wrong, they would be greatly appreciated :slight_smile:

Also, on a similar vain, this other curve wont even offset using the Rhino command. The very strange thing is that this curve wont offset until I translate it a bit. I can even translate it in the x by 1 then in the x by -1 to put it back where it started. This makes offsetting the curve work. There is something very strange at foot…
OtherOffsetBug.3dm (70.9 KB)

[Edit] After some more digging. Im seeing that this curve is invalid, but translating it by 0.000000001 in the x makes it valid. Whaaaaaat?

The offset function returns an array of curves. That might be throwing you off. (It always throws me off). If the length of the returned array is greater than 0, you can loop through them and add them to the document.

As to the offset bug, i think you should make a separate post about that with a title like “[Bug?] Curve won’t offset unless it’s moved first” or something similar.

this is doing the job - even without simplifying.
(run in scripteditor)
(next time it s easier to help if you post a full code - snippet that allows the forum to repeat your error.)

// #! csharp
using System;
using Rhino;
using Rhino.Geometry;
using Rhino.Input;
using Rhino.Input.Custom;
using Rhino.Commands;

void RunCommand(RhinoDoc doc)
{
    // Prompt for a curve
    var go = new GetObject();
    go.SetCommandPrompt("Select a curve");
    go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
    go.Get();
    if (go.CommandResult() != Result.Success)
        return;

    var curveObjRef = go.Object(0);
    var curve = curveObjRef.Curve();
    if (curve == null)
    {
        RhinoApp.WriteLine("No curve selected.");
        return ;
    }

    // Prompt for a point
    var gp = new GetPoint();
    gp.SetCommandPrompt("Select a point");
    gp.Get();
    if (gp.CommandResult() != Result.Success)
        return ;

    Point3d point = gp.Point();
    //
    Curve simpleCrv = curve.Simplify(CurveSimplifyOptions.All,0.001,0.1);
    Curve[] offsets = curve.Offset(point,Vector3d.ZAxis,6,0.001,CurveOffsetCornerStyle.Sharp);
    // Curve[] offsets = simpleCrv.Offset(point,Vector3d.ZAxis,6,0.001,CurveOffsetCornerStyle.Sharp);
    foreach(Curve crvi in offsets)
    {
        doc.Objects.AddCurve(crvi);
    }
    doc.Views.Redraw();
    return ;
}

RunCommand(RhinoDoc.ActiveDoc);

your second example is a invalid curve.
check with
_what
command.
works after simplifying the curve
via script - see code in comments
or via
_ SimplifyCrv Command
which reduces this polyline from around 500 to 120 points

kind regards -tom

2 Likes

This curve is invalid because it has some zero length segments. When curves are transformed short segments are removed in case any were created by the transformation. This makes it valid but changes your geometry.

3 Likes