Check segment overlap is error

I write a code to check the overlap of 2 segment in the polyline, but the error is when these 2 segment do not overlap but return true

def find_overlapping_curves(polycurve1, polycurve2, tolerance=0.01):
overlaps =
Cur1=rs.ExplodeCurves(polycurve1,True)
Cur2=rs.ExplodeCurves(polycurve2,True)
for curve1 in Cur1:
rs.SelectObject(curve1)
for curve2 in Cur2:
rs.SelectObject(curve2)
intersection = rg.Intersect.Intersection.CurveCurve(rs.coercecurve(curve1),rs.coercecurve(curve2), tolerance, tolerance)
if intersection:
it=rs.CurveCurveIntersection(curve1,curve2)
if intersection[0].IsOverlap:
overlaps=[curve1, curve2]
Cur1.remove(curve1)
Cur2.remove(curve2)
break
rs.UnselectObject(curve2)
rs.UnselectObject(curve1)
rs.DeleteObjects(Cur1)
rs.DeleteObjects(Cur2)
return overlaps
CHEC.3dm (32.8 KB)

Hi @xiix.xoox,

This seems to work on your two curves:

import Rhino
import scriptcontext as sc

def test_azure():
    go = Rhino.Input.Custom.GetObject()
    go.SetCommandPrompt("Select first curve")
    go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve
    go.Get()
    if go.CommandResult() != Rhino.Commands.Result.Success:
        return go.CommandResult()
        
    curve0 = go.Object(0).Curve()
    if not curve0:
        return
        
    go.SetCommandPrompt("Select second curve")
    go.EnablePreSelect(False, True)
    go.DeselectAllBeforePostSelect = False
    go.Get()
    if go.CommandResult() != Rhino.Commands.Result.Success:
        return go.CommandResult()
        
    curve1 = go.Object(0).Curve()
    if not curve1:
        return
        
    tol = sc.doc.ModelAbsoluteTolerance
    ccx_events = Rhino.Geometry.Intersect.Intersection.CurveCurve(curve0, curve1, tol, tol)
    if not ccx_events or 0 == len(ccx_events):
        print("No intersectons found")
        return
    
    for i in range(0, len(ccx_events)):
        ccx = ccx_events[i]
        if ccx.IsPoint:
            print("Event[{0}] type = Point".format(i))
        elif ccx.IsOverlap:
            print("Event[{0}] type = Overlap".format(i))        
        

if __name__ == "__main__":        
    test_azure()

– Dale

it’s still the same

import Rhino
import scriptcontext as sc
import rhinoscriptsyntax as rs
def find_overlapping_curves():
go = Rhino.Input.Custom.GetObject()
go.SetCommandPrompt(“Select first curve”)
go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve
go.Get()
if go.CommandResult() != Rhino.Commands.Result.Success:
return go.CommandResult()
curve_in0 = go.Object(0).Curve()
if not curve_in0:
return
go.SetCommandPrompt(“Select second curve”)
go.EnablePreSelect(False, True)
go.DeselectAllBeforePostSelect = False
go.Get()
if go.CommandResult() != Rhino.Commands.Result.Success:
return go.CommandResult()
curve_in1 = go.Object(0).Curve()
if not curve_in1:
return
Cur1=rs.ExplodeCurves(rs.coercecurve(curve_in0),False)
Cur2=rs.ExplodeCurves(rs.coercecurve(curve_in1),False)
tol = sc.doc.ModelAbsoluteTolerance
overlaps =
rs.UnselectAllObjects()
for curve0 in Cur1:
rs.SelectObject(curve0)
for curve1 in Cur2:
rs.SelectObject(curve1)
ccx_events = Rhino.Geometry.Intersect.Intersection.CurveCurve(rs.coercecurve(curve0),rs.coercecurve(curve1), tol, tol)
if ccx_events or 0 != len(ccx_events):
for i in range(0, len(ccx_events)):
ccx = ccx_events[i]
if ccx.IsPoint:
print(“Event[{0}] type = Point”.format(i))
elif ccx.IsOverlap:
overlaps=[curve0, curve1]
Cur1.remove(curve0)
Cur2.remove(curve1)
break
rs.UnselectObject(curve1)
rs.UnselectObject(curve0)
rs.DeleteObjects(Cur1)
rs.DeleteObjects(Cur2)
return overlaps
if name == “main”:
find_overlapping_curves()

Can’t check your code as you’ve only provided screenshots and unformatted text.

If you check the geometry closely in the file you provided, you can see that the segments you indicated do in fact have a very small overlap (approx. 6E-11 units).


(Text Dots in this image indicate curve edit point locations.)

If you explode the curves in your file and process all intersection events, the result is 5 single point intersections and 2 overlap intersections.

You can see the segments at index 4 from both curves produce this small overlap.


(Text Dots indicate curve segment indices. Data paths of the intersection events indicate which curve segments produced the intersection event.)

I just noticed that you are using a cracked version of Rhino.

I thought about deleting the info. I posted above but since I took the time to investigate I will leave it.

Do the right thing and buy a license if you want to continue using Rhino.

-Kevin