Skip to content

Instantly share code, notes, and snippets.

@pgolay
Last active June 18, 2018 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pgolay/3ce685184ee64f1e6b6b714e8b1bc766 to your computer and use it in GitHub Desktop.
Save pgolay/3ce685184ee64f1e6b6b714e8b1bc766 to your computer and use it in GitHub Desktop.
Check clearance between breps or meshes
import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc
def Clearance():
id1 = rs.GetObject("Select a base surface, polysurface or mesh.", 8+16+32, preselect=True)
if not id1: return
if rs.IsMesh(id1):
p1 = rs.GetPointOnMesh(id1,"Set a point near the closest point")
if not p1:return
geo1 = rs.coercemesh(id1)
else:
p1 = rs.GetPointOnSurface(id1,"Set a point near the closest point")
if not p1:return
geo1 = rs.coercebrep(id1)
id2 = rs.GetObject("Select a target surface, polysurface or mesh", 8 + 16 + 32)
if not id2: return
if rs.IsMesh(id2):
geo2 = rs.coercemesh(id2)
else:
geo2 = rs.coercebrep(id2)
intSamples = 64
count = 0
while count<intSamples:
pt = geo1.ClosestPoint(p1)
temp1 = geo1
temp2 = geo2
geo1 = temp2
geo2 = temp1
count += 1
#rs.AddPoint(pt)
if count < intSamples : p1 = pt
ids = []
for item in rs.AddPoints([pt, p1]):
ids.append(item)
ids.append(rs.AddLine(pt, p1))
if len(ids) > 0: rs.SelectObjects(ids)
print "Clearance is " + str(round(p1.DistanceTo(pt), 3))
if __name__ == "__main__": Clearance()
@pgolay
Copy link
Author

pgolay commented Jun 18, 2018

Took out an extra set of get points...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment