Need an algorithm to generate center line

Hey - for past couple of weeks I’ve been struggling to create and algorithm that generates center line (red curves in the attached image) of any given one or two closed curves (black curves in the attached image). So, I was wondering if anyone can help me with this problem.

curves.3dm (44.1 KB)

Thanks,

1 Like

Hello
you are after a sort of Medial Axis/Tween curve. You will find on this forum many discussion on that but I am not sure there is a reliable way to do what you want.

1 Like

for example here…

1 Like

Here’s a hacked together script (from some parts of others I did in the past) - it will do all of the curves you posted in the file above except one…

The reason being is if you have one closed curve, it assumes it is sort of a capped offset and that the ‘ends’ are the shortest segments in the curve. The one that fails has shorter segments inside. I don’t know how to do this otherwise for the moment, aside from making the user pick the ends to remove manually if it can’t figure it out automatically - it might be possible to add that later. It tries to establish a matched set of curves (number of segments and order) and then creates a mid curve between each of the matching segments and joins the result. It will probably have a number of cases where it fails, but maybe it’s useful… FWIW.

FindMidCurve.py (8.3 KB)

2 Likes

Check this idea

center line.gh (16.9 KB)

1 Like

@anon39580149 Thank you so much for this. My mind is blown right now…

I just have a question, is there any way to right this same algorithm in C#? the program that I’m working on is a Rhino tool, so I don’t think that I have access to grasshopper methods and components.

Again, I really appreciate your help.

You can use Grasshopper script in Rhino with Grasshopper player.
I don’t know if it is possible to convert this script to c# code for Rhino