Using kangaroo2.dll in RhinoCommon


I’m trying to figure out how to use the kangaroo2.dll in a RhinoCommon project. I want to achive something simple, equal to this picture:

A couple of lines should always be shorten to a given length, but I can not figure out how to do actually do that. I can not find any kind of documentation(if there is any?) and in VS no information regarding methods exists aswell.

Here is my current code as a textfile: kangaroo_dll.txt (3.2 KB)

I’m open to other suggestions aside from using the kangaroo.dll. Actually, I would appreciate that, but in the end getting this thing to run would suffice.

Hi Roger,
I’m not really clear of the aim here.
Do you definitely want to make a Rhino command plugin?
Or is there a specific geometric task you want to do and you are looking at any way to achieve this?
If you are open to using Grasshopper that’s an easier way to start, either by using the existing components, or scripting in a Grasshopper script component.
There are a few sample scripts here:

Hi Daniel,

thank you for your reply.

The target is to recompute a curve into segments which are always divisible by 500 as part of a bigger solution. I was given a .gh file as a template which uses Kangaroo to achive this, so my idea after failing my first attempts was to look into using the kangaroo2.dll inside RhinoCommon.

Here is what I try to achive both in picture and .3dm form:

targetCurves.3dm (38.4 KB)

The red curve is what I want to achive in RhinoCommon. As you can see, the gh script does this already but is way to heavy and GH itself is just not suitable for our project.

I’m not sure what you mean by too heavy. Here’s an example definition for the polyline. It solves pretty much instantly (around 7ms). It looks from your first screenshot like you were trying this in Kangaroo 1? (7.3 KB)
or here for the curved one: (8.9 KB)

As I said, this problem is part of a much larger solution. The entire prototype solution in GH takes about five minutes and is lacking many of the essential features of the target. I can not go into more details due to NDA, but it is simply not possible to do with Grasshopper and a hybrid solution is out of the question aswell.

Edit: yes the person who gave that script to me used Kangaroo1.

Kangaroo2 is orders of magnitude faster than Kangaroo1 for this sort of thing.
Here’s a very short script that does the same thing as the last definition.
Sharing it here within a gh script component, but the operation is just the same when using it in a Rhino (14.4 KB)

1 Like

Thank you that worked perfectly.I still have some finetuning to do but I think giving every segment a custom target length instead of a flat 500 will do that.

Kangaroo2 is orders of magnitude faster than Kangaroo1 for this sort of thing.

Not doubting that, but once hundreds or sometimes thousands of breps are added to the document grasshopper cant compete with RhinoCommon.

Thank you again for your help.

1 Like

I think it might work best to not split at all the sides you want to keep straight, and set a rest length for them of the closest multiple of 500, and only use multiple segments where you have curved sides

yes, just added this to process the segments and it works like a charm:

    List<Curve> segmentsBefore = curve.DuplicateSegments().ToList();
    List<Line> segments = new List<Line>();

    foreach(var segment in segmentsBefore)
            segments.Add(new Line(segment.PointAtStart, segment.PointAtEnd));
            double[] parameters = segment.DivideByLength(500, true);
            List<Curve> subsegments = segment.Split(parameters).ToList();

            subsegments.ForEach(sub => segments.Add(new Line(sub.PointAtStart, sub.PointAtEnd)));


for (int i = 0; i < segments.Count; i++)
                Line c = segments[i];

                double len = c.Length;
                int divisor = Convert.ToInt16(len / 500);
                int targetLength = 500 * divisor;

                goals.Add(new KangarooSolver.Goals.Spring(c.From, c.To, targetLength, 1));
                PS.AssignPIndex(goals[i], 0.0001);

inside the loop.

1 Like