C# Transform.ProjectAlong vs GH ProjectAlong – why different?

Hey everyone,
I’m trying to project a curve using Transform.ProjectAlong in C#, but the result doesn’t match the ProjectAlong component in Grasshopper.
Any idea why? How can I get the same result in C#? Could it be a data type issue?

Thanks!

TransformProblem.gh (19.2 KB)

Hi @朱钟鸿,

Can you run Rhino’s SystemInfo command and post it in a reply?

Thanks,

– Dale

Ok. This one took me a minute to figure out what was going on. The primary issue is that you’re duplicating an arc-like curve which is trying to maintain it’s rigid arc status when it performs the transformation. Instead of calling DuplicateCurve, really what you want to do is to convert the arc into a standard curve, which internally calls a MakeDeformable method. When you convert the arc to a curve and then run the transformation on it, it will work as expected.
In fact, this is exactly what’s happening with the Grasshopper component. If you hover over the G-input, you’ll notice the data type for the input is an “arc-like curve”. But, if you hover over the G-output, the result of the transformation is a “planar curve”. The component has performed a casting operation to convert this into a curve before making the transformation.
So, ideally, you’re code should look like this:

private void RunScript(Curve x, Plane y, Vector3d z, ref object a)
{
    var aa = x.ToNurbsCurve();
    aa.Transform(Transform.ProjectAlong(y, z));
    a = aa;
}

I think if you run this, it should work for you.

Thank you so much for the detailed explanation!

This issue has been driving me crazy. So for special rigid geometries like arcs, is converting to NurbsCurve the best practice?

I noticed that even after converting an Arc to an ArcCurve, it still wouldn’t transform correctly.

Before transformation, DuplicateCurve() and ToNurbsCurve() appear to produce the same result.