Find similar curves

I have two question about similar curves
1:
I have many curves.
and need using C++ codes to divide them into groups along the curves‘s Similarity。
how can I do?

2:I have two group curves named gruop A and B (these curves are not sorted )
which can be merged to two closed curves.
one closed curve is inner the other.
one curve in gruop A has a similartity curve in gruop B.
How can I find the corresponding curve in gruop B?

similarCurves.rar(6.0 KB) is a just simpely test sample curves.
in this example: I need find the same color curve along the outside curves.

1.) How do you define “similarity?”

2.) The RhinoMergeCurves() SDK function will join these into 2 closed curves. Is this what you are looking for?

1: the shape of curves are similarity.

2:RhinoMergeCurves can make them to two closed curves
but before that I need find the same color curve along the outside curves.
you can see my test sample curves,maybe be can unstand what I want to do.

1.) So by similar shapes, you mean “find all lines” or “find all circles”? If this is the case then you might take a look at this code sample and see if it gives you any ideas:

https://github.com/mcneel/Rhino5Samples_CPP/blob/master/SampleCommands/cmdSampleClassifyCurve.cpp

2.) To find curves that have the same color, you will need to use a CRhinoObjectIterator class to iterate through all objects in the document.

Once you have an object, you can perform whatever test you need.

For example:

https://gist.github.com/dalefugier/6117713

Hope this helps.

dale:
Thanks for you help
maybe I explained my problem not clearly.
These ideas are not I needed.

I am sorry for my poor english.
I will think how to sovle these problems myself.
If I still have’t ideas,I will try explain my problem more clearly.
Thanks again.

If you need help with language conversion, you always email @kelvin at kelvin@mcneel.com.

Hey Dale,

Good morning.

I am reviving a thread from last year to ask “why does it seem so difficult to come up with a script that can find duplicate objects that do not overlap?” Any kind of duplicate objects, from a simple two point line to a closed four sided curve loop, to more complicated stuff. I posted a request in the Scripting forum and the only answer I got was from Mitch who has a script for finding closed objects that have the same volume.

Is there something I’m missing?

Thank you.

I use a very large spatial hashtable to find overlapping ( or similar) curves:
The nice thing about this aproach is that it keeps the runtime linear.

import rhinoscriptsyntax as rs

from collections import defaultdict as defD

crvs = rs.GetObjects(filter=rs.filter.curve)

tolerance = 1.5

# hash function considering tolerance
def tup (pt):
    x=int(pt.X/tolerance)
    y=int(pt.Y/tolerance)
    z=int(pt.Z/tolerance)
    return x,y,z
    
    
D={}
X=defD(int)
for crv in crvs:
    pts=rs.DivideCurveLength(crv,tolerance*0.7) # space points a bit thighter tan tolerance
    tp=0,0,0
    for p in pts:
        t=tup(p)
        if t<>tp:
            if t in D:
                ocrv=D[t]
                c2 = ocrv,crv
                X[c2] +=1
            else:
                D[t]=crv
            tp=t


for (t,o),k in X.items():
    if k > 5: # require an overlap at 5 locations within tolerance ?
        lo=rs.CurveLength(o)
        lt=rs.CurveLength(t)
        if lo < lt: # select the shorter of the two curves
            rs.SelectObject(o)
        else:
            rs.SelectObject(t)