def check_collisions_w_parts(self, parts): ## multiple collider with associated connections if self.multiple: valid_colliders = [] self.valid_connections = [] count = 0 for geo in self.geometry: valid_coll = True for part in parts: for other_geo in part.collider.geometry: if len(Intersection.MeshMeshFast(geo, other_geo)) > 0: valid_coll = False break if valid_coll == False: break valid_colliders.append(valid_coll) if self.set_connections and valid_coll: self.valid_connections.append(count) if valid_coll and self.check_all == False: break count+=1 if True in valid_colliders: return False return True ## simple collider else: for geo in self.geometry: for part in parts: for other_geo in part.collider.geometry: if len(Intersection.MeshMeshFast(geo, other_geo)) > 0: return True return False
def check_collisions_by_id(self, parts, ids): ## multiple collider with associated connections if self.multiple: valid_colliders = [] count = 0 for geo in self.geometry: valid_coll = True for id in ids: for other_geo in parts[id].collider.geometry: if len(Intersection.MeshMeshFast(geo, other_geo)) > 0: valid_coll = False break valid_colliders.append(valid_coll) if valid_coll and self.check_all == False: break count+=1 if True in valid_colliders: return False return True ## simple collider else: for geo in self.geometry: for id in ids: for other_geo in parts[id].collider.geometry: if len(Intersection.MeshMeshFast(geo, other_geo)) > 0: return True return False
def RunCommand(): rc, circle = Rhino.Input.RhinoGet.GetCircle() if rc != Rhino.Commands.Result.Success: return rc doc.Objects.AddCircle(circle) doc.Views.Redraw() rc, line = Rhino.Input.RhinoGet.GetLine() if rc != Rhino.Commands.Result.Success: return rc doc.Objects.AddLine(line) doc.Views.Redraw() lineCircleIntersect, t1, point1, t2, point2 = Intersection.LineCircle( line, circle) message = "" if lineCircleIntersect == LineCircleIntersection.None: message = "line does not intersect circle" elif lineCircleIntersect == LineCircleIntersection.Single: message = "line intersects circle at point ({0},{1},{2})".format( point1.X, point1.Y, point1.Z) doc.Objects.AddPoint(point1) elif lineCircleIntersect == LineCircleIntersection.Multiple: message = "line intersects circle at points ({0},{1},{2}) and ({3},{4},{5})".format( point1.X, point1.Y, point1.Z, point2.X, point2.Y, point2.Z) doc.Objects.AddPoint(point1) doc.Objects.AddPoint(point2) print message doc.Views.Redraw()
def check_hard(self, pt, collider): if self.check_soft(pt): for geo in collider.geometry: if len(Intersection.MeshMeshFast(self.geo, geo)) > 0: return False return True else: return False
def check_hard(self, pt, collider): if self.check_soft(pt): for geo in collider.geometry: if Intersection.MeshPlane(geo, self.plane) is not None: return False return True else: return False
def wallCheck(self, point, dir): dist = self.stepsize * 0.05 dir = rs.VectorUnitize(dir) * dist up = g.Vector3d.ZAxis * dist pt1 = point + up pt1 = pt1 + dir pt2 = pt1 + dir pt3 = point + 2 * dir line1 = g.Line(pt1, pt2) line2 = g.Line(pt2, pt3) test = [ s.MeshLine(self.mesh, line1)[1], s.MeshLine(self.mesh, line2)[1] ] print test #if test == [None, None]: # return True return False
def impactPoint(startPoint, facadeMesh, windVect): # does the rain line touch the facade? ray = g.Ray3d(startPoint, windVect) num = s.MeshRay(facadeMesh, ray) if num <= 0: # the rainLine does not touch the facade return startPointDrop = ray.PointAt(num) # impact point impactPoints.append(startPointDrop) rainLines.append(g.Line(startPoint, startPointDrop)) return startPointDrop
def nextSurf(self): # find the next intersection with the mesh self.pos = g.Point3d.Add(self.pos, g.Vector3d(0., 0., -1.) * self.stepsize / 10) ray = g.Ray3d(self.pos, g.Vector3d(0., 0., -1.)) num = s.MeshRay(self.mesh, ray) if num > 0: # if it does not exists self.nextCrv() newPoint = ray.PointAt(num) #self.waterPath.append(g.Line(self.pos, newPoint)) # this line can be unhashtagged if we want to follow the water path off the facade self.updatePos(newPoint) self.state = 'on' # the waterflow is on the facade again else: self.finish()
def MeshRay(self, ray): startPt = ray.Position l = [] for i in range(self.length): num = s.MeshRay(self.obj[i], ray) if num > 0: pt = ray.PointAt(num) l.append([ray.PointAt(num), i]) if not l: # if the list is empty, return nothing return ([]) else: # return the closeset point and the index of the mesh it is on tempDist = [startPt.DistanceTo(l[i][0]) for i in range(len(l))] index = tempDist.index(min(tempDist)) return l[index]
def nextStepOff(self): # find the next intersection with the mesh self.pos = g.Point3d.Add(self.pos, g.Vector3d(0., 0., -1.) * self.stepsize / 10) ray = g.Ray3d(self.pos, g.Vector3d(0., 0., -1.)) num = s.MeshRay(self.mesh, ray) if num > 0: # if the water drops on the facade newPoint = ray.PointAt(num) self.state = 'landing' self.updateData(newPoint) self.state = 'on' self.updatePos(newPoint) else: self.state = 'finished'
def projectPtOnSrf(attractorPt, targetSrf, pt): r = rs.AddLine(attractorPt, pt) r = rs.ScaleObject(r, attractorPt, (10, 10, 10)) dom = rs.CurveDomain(r) crv = rs.coercecurve(r) srf = rs.coercesurface(targetSrf).ToNurbsSurface() inv = Interval(dom[0], dom[1]) rs.DeleteObject(r) xobj = Intersection.CurveSurface(crv, inv, srf, 0.1, 1) return xobj[0].PointB
def DivDist2D(crv, dist): ## 以下を改造しました ## Hiroaki Saito : GH C#_Divide Distance With List ## https://openddl.com/post/166/ ## 閲覧:2021/6/2 pln = Plane.WorldXY points = [] paramList = [] if crv: tmpParam = 0. pt = crv.PointAtStart dummy_out = System.Double(0) tmpParam = crv.ClosestPoint(pt, dummy_out)[1] points.append(pt) paramList.append(tmpParam) for i in range(len(dist)): d = System.Double(dist[i]) circle = Circle(pln, points[i], d) tmpCrv = circle.ToNurbsCurve() ci = Intersection.CurveCurve(crv, tmpCrv, 0, 0) addCheck = False tmpList = sorted(ci, key=lambda x: x.ParameterA) for item in tmpList: tmpParam = item.ParameterA if tmpParam > paramList[i]: points.append(item.PointA) paramList.append(tmpParam) addCheck = True break if not addCheck: break pt = crv.PointAtEnd points.append(pt) return points
def pathDrawing(startPoint, facadeMesh, windVect, stepSize, maxSteps, endPlane): # does the rain line touch the facade? ray = g.Ray3d(startPoint, windVect) num = s.MeshRay(facadeMesh, ray) if num <= 0: # the rainLine does not touch the facade return [], [], [] startPointDrop = ray.PointAt(num) # impact point # creation and initialization of the RainDrop OBJECT drop = RainDrop(startPointDrop, facadeMesh, windVect, stepSize, maxSteps, endPlane) i = 0 # loop that draw the water path while drop.state != 'finished' and i < drop.maxsteps: i += 1 if i > 5: drop.check = True # begin to check if drop.check == True: # check falling and accumulation conditions drop.accumulationCheck() drop.anglesCheck() if drop.state == 'on': # if the waterflow is on the facade drop.nextStep() if drop.state == 'off': # if the waterflow is off the facade (did not used if self.check == 'off' to gain a test) drop.check = False # stop checking until it reaches the facade again drop.nextSurf() i = 0 # re initialisation of the count to be sure that it is not overtaken # creation of the curves curves = [] for cu in drop.waterPath: curves.append(cu) if len(drop.waterPath) == 0: print 'missed' return curves, startPointDrop, g.Line(startPoint, startPointDrop)
def check_intersection_w_line(self, ln): for geo in self.geometry: if len(Intersection.MeshLine(geo, ln)[0]) > 0: return True return False