CADs curve pair matching

Hi, I currently have two CAD files, and they are all layer organized well. I would like to implement tween curve component morph curves from one CAD file to the other.

My overall goal is to SMOOTHLY morph one group of curves from CAD_A file to the curves from CAD_B.

I have checked they are all the same amount of curves from both CAD files.
I certainly need a clever sorting method to help ordering these curves.

I have been using LINQ

  1. sorting with PointAtStart
  2. sorting with the GetBoundingBox(true).Center
  3. sorting with the distance to the Origin

but unfortunately, none of them work properly.

This might be a hard problem since from CAD_A to CAD_B, some of the curves are not only translation, scaling and also rotation.

I also try to sort with the relationship from one curve to other using the recursive closest point method, discussed in this article.

And this is what it looks like

but as method above, they are not only translate but also rotate. It’s hard to write a code to identify the proper pairs.

Also, sorting might just be one of the solution approach. Though I am not so sure, if there’s some other library(OpenCV) for visual recognize I could use, that will be great.

Here is the files. Thanks
ForQuestion.3dm (1.2 MB) (386.0 KB)

Sorting your points with the standard Sort Points component fails due to tiny incremental differences.

Here’s a possible solution. I internalized one set of your curves. (176.9 KB)


If they would be branched by scissor pair it should be an easy task.
I would “branch” them manually if there is just the amount as on your screencapture.

Thank you for this approach. I can see the potential behind this one. Since I have some other curves from CAD_A and CAD_B need to morph, I am still seeking for rather general approach to this topic. The partition list divide to the 2 way is clever, but I am afraid it will not suitable for the other matching CAD curve situation.

For say, I also need to consider about the size of the detail drawing like this part.

Knowing the correspond points are definitely a good progress for me, but for the detail part curve, I still need a way to match them, in order to use tween curve component.

Good thing to use tween curve in this case, might be I want the detail drawing in the same size but the if the rod part length changed it gradually change accordingly.


  • blue: rod part
  • red: detail parts

That’s what I concern.

The cleanest data might be the sorted 1140 curves, which match perfectly with the 1140 curves from the other group, so that I can use tween curve to morph them right away.

Thank you!

Thank you for your reply. I agree with you, but it’s just a piece of drawings about the whole CAD file. There’re around 10000 curves in totally. Since it’s so detailed, I couldn’t select it cleverly just by clicking. That’s why I thought I need a sorting approach for my problem.
But still, your opinion is right to the point. Appreciate it. Thanks.

I’m not sure what you want to do with tween curves….

Usually a tween curve is a curve in between two other more or less side by side curves.

1 Like

wow, this was a smart approach :+1: :clap:

don’t know if the following is a real step forward (a bit confused for sure…)
shape in brep on the pipes generated on the axis of the rods might be one way to rebuild a tree where each branch has only the elements of a given rod
→ group marked “1”

at this point I thought an oriented bounding for each group of lines could do the trick, in such a way to create a new fake axis that travels in a non perfectly non-longitudinal way along each group (in such a way it would be easier to sort what is on the left and what is on the right of each fake-axis)
original curves are then sorted along curve using this fake axis:

the tweening each curve with its relative, and also the flipped version of its relative (I thought I could then cull them based on final length, because artifacts would have a very different length from the original) … but the final -unculled- tween is still weird in some points :slight_smile: (186.3 KB)

a lot of suffering with just mediocre results, a perfect representation of life itself :heart:

this said, unless you have 2 million drawings on which you want to apply this, I would consider a different approach :slight_smile:


Thank you so much. That’s what I wanted. Sorry for not being clear about my intentions. Yes, morphing smoothly using tween curves was what I meant.

Thank you, Mr. Inno and Mr.Martin. Appreciate it.

Some relative topics I’ve been thinking about these days is Point-set registration - Wikipedia. I think the current solution is only suitable for this specific CAD, which is already did a great job(HUGH THANKS), but I am wondering if anyone have done this in Grasshopper before.

Given two group of unsorted points(location).
Probably with some picture recognition for some aided reference points, make the point-set pair match. If there’re relevant topics, experience, libraries, or algorithms ever been implement in GH or .NET, I would like to dive in a bit deeper. Thanks

Sorry for not being clear about the topic. Mr. Inno’s file is the thing I was seeking out. Your file well organized the group, that’s amazing.