Last active
June 18, 2018 17:39
-
-
Save pgolay/3ce685184ee64f1e6b6b714e8b1bc766 to your computer and use it in GitHub Desktop.
Check clearance between breps or meshes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Took out an extra set of get points...