Identify self-intersecting curves without adding points to Rhino Document

With reference to this previous post on an unsupported command for detecting self-intersecting curves, I’d like to do the same thing but without adding any points to the Rhino Document. I would just need a True/False output (True - there is a self-intersection, False - there is none), and no other outputs (the unsupported command adds points to the intersection locations, and this is not necessary for my script).

I am aware that I can run the command using the rs.Command(macro) function. While this does return a True/False based on the existence of the intersections, I cannot retrieve the points added to the intersections. Is there a Python scripting way to go about this (I’m completely only scripting in the RhinoPython editor)? What other workarounds are possible?

You could try modifying Mitch’s script by removing the part that adds points.

Option Explicit
'Script written by Mitch
'Version Friday, 01 June 2012

Call SelSelfIntersectingCrvs()
Sub SelSelfIntersectingCrvs()
	Dim arrCrvs,strCrv,arrSIPts,strGroup,res,tol
	tol = Rhino.UnitAbsoluteTolerance()
	arrCrvs = Rhino.ObjectsByType(4)
	If IsArray(arrCrvs) Then
		Call Rhino.UnselectAllObjects()
		Call Rhino.EnableRedraw(False)
		For Each strCrv In arrCrvs
			res = Rhino.CurveCurveIntersection(strCrv,, tol)
			If IsArray(res) Then 
				Call Rhino.SelectObject(strCrv)
				arrSIPts = AddSIPoints(res)
				strGroup = Rhino.AddGroup
				Call Rhino.AddObjectsToGroup(arrSIPts, strGroup)
				Call Rhino.AddObjectToGroup(strCrv, strGroup)
			End If	
	End If
	Call Rhino.EnableRedraw(True)
End Sub

Function AddSIPoints(arr)
	Dim arrPts(),i,n
	i = -1
	For n=0 To Ubound(arr, 1)
		i = i + 1
		ReDim Preserve arrPts(i)
		arrPts(i) = Rhino.AddPoint(arr(n, 1))
		If arr(n, 0) = 2 Then
			i = i + 1
			ReDim Preserve arrPts(i)
			arrPts(i) = Rhino.AddPoint(arr(n, 2))			
		End If
	Call Rhino.SelectObjects(arrPts)
	AddSIPoints = arrPts
End Function


Assuming it is the method you are looking for, you could call the Intersection.CurveSelf method directly.

Here is the current python version of my script, I added an option to not create points. (1.4 KB)


1 Like

Thanks @Helvetosaur, @ Terry_Chappell and @AndersDeleuran for the suggestions. Both Intersection.CurveSelf (where I’d need to look for the Rhino Curve in the Object Table first) and rs.CurveCurveIntersection (where I can just wait for a None or List output) seem to fit what I’m looking for, which is an indicator of whether a curve is self-intersecting.

(All these solutions work for self-intersecting Polylines, but I’m working on a different approach for a self-intersecting polygon made up of separate curves where two or more intersect.)

In my experience, a PolylineCurve with CurveSelf Intersection does actually not act as expected. Just FYI.