I see that there is a convert option that does this job, but I can’t find any functions in the Rhinocommon SDK that can do the same thing in one step. Does anyone know how to convert a freeform curve into arcs? Is there a way to see the algorithm behind the convert feature?
Convert option where? Grasshopper only provides ways to convert curves to polylines. Perhaps you’re using a plug-in component?
It’s in Rhino: Curve->Convert->Curve To Arcs
I was confused because you posted this in the Grasshopper Developer forum, whereas this concerns Rhino commands and Rhino SDK. The ConvertCurveToArc logic uses bi-arcs as I recall which are not exposed in the SDK. Grasshopper also has a bi-arc algorithm (but that code is part of the CurveComponents.gha project, not Grasshopper.dll).
I copied my C# bi-arc fitter into a GH C# component. The attached file contains a script component which creates a collection of tangent bi-arcs that approximate a curve.
biarcfitter.gh (3.9 KB)
There are two problems with the code.
1- the last or the first arc part is missing.
2- if there is a kink on the curve, the code doesn’t work well.
here is screenshot
Try the adjusted script attached. It can create very short biarcs near kinks, if the original curve division yielded a point nearby. This can be handled but would require additional code.
biarcfitter.gh (6.9 KB)
Thanks, that works. And also thanks for the really fast reply.
Hi David, thanks for your script! I am trying to understand it more by reading your code.
One question I have here is how you adjust the ratio/factor in the code. It seems that you are using 0.5(factor) / 1.0 (ratio) as the initial guess, which means it is a one arc instead of a bi-arc. I understand the logic. But I assume there should be some algorithm that adjust/optimize the ratio to find the bi-arc. I did not see it. Maybe I missed it. Do you mind to point out where is it? Thank you!
You can also implement
Curve.ToArcsAndLines now, quick example here:
Thanks a lot for the c# component and scripting! I would like to second the question that @jingwen.wang suggested.
I am also looking to adjust the ratio of the biarc, from the default 0.5 to 1, meaning I wonder like to only bias towards the first arc to approximate the each segment of the division. It is possible to so with Grasshopper BiArc component, however I wonder if its possible to do so within the c# script?