I am looking for a script, RVB, to find curves that are contained within another curve
All the curves lay on the same plane
All the curves are closed and do not intersect, no self-intersections
I am not concerned with multiple nesting, curves within at a second level, I can have the script that finds nested curves move them to a new layer and rerun the script on that layer
the same is available for point containment - if you already know that there are no intersections this will be much faster - just test a single point of the curve
thanks!, any thoughts and how to use it? I mean, in the script, it will have to test every curve against every other (on a given layer), but it would be redundant if I just step through all the curves, and yes, there are not intersections, self or otherwise, I am fixing that manually, and it is very tedious
there are 36422 curves, they are on 7 separate layers so I can deal with a few thousand at a time
there are maybe 300 or so self intersecting curves per layer, I am about 1/2 done dealing with those, manualy
I will do some more ‘processing’ with these, then export to Illustrator
Part of the process it to extrude them to a point, Rhino won’t do that if there are self intersecting curves (it asks if you want to continue, but then does not)
the above link i posted has a rvb sample - this should get you started.
Const rhObjectCurve = 4
Dim strCurve1, strCurve2, intResult
strCurve1 = Rhino.GetObject("Select first curve", rhObjectCurve)
strCurve2 = Rhino.GetObject("Select second curve", rhObjectCurve)
If Rhino.IsCurvePlanar(strCurve1) And Rhino.IsCurvePlanar(strCurve2) Then
If Rhino.IsCurveClosed(strCurve1) And Rhino.IsCurveClosed(strCurve2) Then
If Rhino.IsCurveInPlane(strCurve1) And Rhino.IsCurveInPlane(strCurve2) Then
intResult = Rhino.PlanarClosedCurveContainment(strCurve1, strCurve2)
If intResult = 0 Then
Rhino.Print "The regions bounded by the curves are disjoint."
ElseIf intResult = 1 Then
Rhino.Print "The two curves intersect."
ElseIf intResult = 2 Then
Rhino.Print "The region bounded by Curve1 is inside of Curve2."
Else
Rhino.Print "The region bounded by Curve2 is inside of Curve1."
End If
End If
End If
End If
but:
with brut force
36422 * 36421 / 2 = 663 Mio pairs / comparisons (each curve against each other)
so you will need some nice logic.
make sure, as soon as a curve is identified inside another not to compare it against any outside curves, you will need some nice logic to avoid unnecessary comparisons.
some initial bouningbox checking might help for performance. c# / python - rhinocommon will be nicer for this kind of algorithms… (there is also rtree)
This might be quite challenging with vbscript.
share some code and sample geometry to get more help, so we see more precisely where you stuck.
I do have the relevant curves on there layers, they have different ‘meanings’, so each curve only gets tested against maybe a fourth of the total
And I have one thought, starting with the first curve, check to see if it is on the current layer, then start testing it, stop the test if is ‘inside’, at that point, assign it to a different layer, then it won’t be evaluated again
I am very familiar with VB, never got around to the other languages
This is an old script from my Python library, I’m just curious how fast it runs on your 36K curves. Probably not very. I did not try to optimize it much. To do so I think it would require something like an rTree structure (based on physical locations of objects) to restrict the search radius for each object and thus eliminate searching objects further away.
Another tactic I have used in the past is to artifically create a selection grid - sort of a manual “tree” and only work on say the objects in the grid square plus the neighbors. But the grid needs to be sized appropriately to the objects i.e. you want the grid squares to be large enough so that they contain some full objects but not too large that they contain many of them.
With some kind of grid optimization, it would probably run in a second or two… It was also designed to detect multiple nesting levels, if there were only two then it would also be a lot faster.