def collisionDetection(used_timber_list, not_used_timber_list, unused_timber, id_connect): num_used_timber = len(used_timber_list) num_not_used_timber = len(not_used_timber_list) sum_timber = num_used_timber + num_not_used_timber timber1 = unused_timber # これから生成するTimber count = 0 # timber1と他のused_timberが衝突していない時のカウント # 衝突判定(unused_timberとused_listのtimber同士の接触判定) for i in range(num_used_timber): # 接合部は衝突とみなさない if i == id_connect: count = count + 1 # 接合部材以外のused_timberとの衝突判定 else: timber2 = used_timber_list[i] curve = rs.IntersectBreps(timber1.surface, timber2.surface) # 衝突していない場合 if curve is None: count = count + 1 # 衝突している場合 else: # 衝突部に目印の球体を生成 --> ただの目印なので接触処理するときはコメントアウトしてもらえればと # mark_sphere = createMarkSphere(curve) # rs.ObjectLayer(mark_sphere, "collision") # objectを削除 rs.DeleteObject(curve[0]) break # 衝突判定(unused_timberとnot_used_listのtimber同士の接触判定) for j in range(num_not_used_timber): timber2 = not_used_timber_list[j] curve = rs.IntersectBreps(timber1.surface, timber2.surface) # 衝突していない場合 if curve is None: count = count + 1 # 衝突している場合 else: # 衝突部に目印の球体を生成 --> ただの目印なので接触処理するときはコメントアウトしてもらえればと # mark_sphere = createMarkSphere(curve) # rs.ObjectLayer(mark_sphere, "collision") # objectを削除 rs.DeleteObject(curve[0]) # unused_timberがどの部材とも衝突してない場合 if count == sum_timber: return False # unused_timberがいずれかの部材と衝突している場合 else: return True
def collisionDetection_bridge(used_timber_list, not_used_timber_list, unused_timber, id_connect_1, id_connect_2): num_used_timber = len(used_timber_list) num_not_used_timber = len(not_used_timber_list) sum_timber = num_used_timber + num_not_used_timber count = 0 timber1 = unused_timber for i in range(num_used_timber): # 接合部は衝突とみなさない if i == id_connect_1: count = count + 1 elif i == id_connect_2: count = count + 1 # 接合部材以外のused_timberとの衝突判定 else: timber2 = used_timber_list[i] curve = rs.IntersectBreps(timber1.surface, timber2.surface) if curve is None: count = count + 1 else: # 衝突部に目印の球体を生成 --> ただの目印なので接触処理するときはコメントアウトしてもらえればと # mark_sphere = createMarkSphere(curve) # rs.ObjectLayer(mark_sphere, "collision") # objectを削除 rs.DeleteObject(curve[0]) for i in range(num_not_used_timber): # 接合部材以外のused_timberとの衝突判定 timber2 = not_used_timber_list[i] curve = rs.IntersectBreps(timber1.surface, timber2.surface) # 衝突していない場合 if curve is None: count = count + 1 # 衝突している場合 else: # 衝突部に目印の球体を生成 --> ただの目印なので接触処理するときはコメントアウトしてもらえればと # mark_sphere = createMarkSphere(curve) # rs.ObjectLayer(mark_sphere, "collision") # objectを削除 rs.DeleteObject(curve[0]) # unused_timberがどの部材とも衝突してない場合 if count == sum_timber: return False # unused_timberがいずれかの部材と衝突している場合 else: return True
def RemoveSurfacesIfAnyIntersectBoundary(self, surf, boundaries): """ checks if a surface intersects the boundary and deletes the surface An auxilliary method to trim extruding fractures. Parameters ---------- surf: GUID guid of a Rhino surface boundaries: list list of boundary guids """ # Checks if a surface intersects a boundary # If so, it deletes it and any created intersections # Could run this with any set of boundary surfaces # Intended to run with the CreateSetOfExtendedBoundaries function for boundary in boundaries: intersections = (rs.IntersectBreps(boundary, surf)) if intersections is not None: # If there are intersections # Delete this surface rs.DeleteObject(surf) # delete the surface from domain fractures list self.my_fractures.remove(surf) # Delete all created intersections for inter in intersections: rs.DeleteObject(inter) return True # WHY RETURN TRUE AND FALSE? return False
def TestIntersection(obj, tester): # there are a few possible intersection methods in rhinoscriptsyntax # as an initial setup only a few intersections are handled # to make this script faster and more robuste best would be to intersect not with rhinoscriptsyntax # But use RhinoCommon methods instead. # #for now only rhinoscriptsyntax methods are used as an example below: # if both are breps ( (poly)surface or extrusion if rs.IsBrep(obj) and rs.IsBrep(tester): intersections = rs.IntersectBreps(obj, tester) if intersections: #Delete intersections if they were made rs.DeleteObjects(intersections) return True if rs.IsMesh(obj) and rs.IsMesh(tester): intersections = rs.MeshMeshIntersection(obj, tester) if intersections: #This method does not create a curve but returns a list of points #so nothing to delete return True #Mixed input needs to be handled different as is with curves. #if either is a mesh the other needs to be converted to a mesh as well #catchall return False return False
def Intersect(self, other): """ function to check if a fracture intersects another Parameter ------- other: guid guid of the second fracture """ # inputs are frcature instances in fracture list curveA = self.fracture_GUID # check for intersection intersection = rs.IntersectBreps(curveA, other.fracture_GUID) # if no intersection if intersection is None: print('The fractures do not intersect') else: # go through the list of intersection for x in intersection: # check it's a line! if rs.IsLine(intersection[0]): # get intersection length length = rs.CurveLength(intersection[0]) # print a statement print( 'Fracture intersect, the length of intersection\ is:', length)
def cutAtPlan(level): planPlane = rs.AddPlaneSurface([-1000,-1000,level], 3000, 3000) baseLayer = rs.AddLayer("60_PLANS") newParent = rs.AddLayer("PLAN_"+str(level), parent = baseLayer) origLayer = rs.CurrentLayer() shortName = rs.LayerName(origLayer, fullpath = False) #newChildsParent = rs.AddLayer( , parent = newParent) newChild = rs.AddLayer(shortName, parent = newParent, color = rs.LayerColor(origLayer)) rs.CurrentLayer(newChild) objs = rs.ObjectsByLayer(origLayer) #if len(objs)<1: # skip = True intersectCrvs = [] tempCrv = None for obj in objs: if rs.IsBrep(obj): tempCrv = rs.IntersectBreps(obj, planPlane) if tempCrv != None: intersectCrvs.append(tempCrv) for crv in intersectCrvs: if not None: rs.ObjectLayer(crv, newChild) rs.DeleteObject(planPlane) rs.CurrentLayer(origLayer)
def TotalLengthOfFractures(self, fracture_guid_list, cut_plane): """ Function to intersect fractures and return the total length of fractures in the cut plane Parameters ---------- fracture_guid_list: list list containing domain fractures' guids cut_plane: guid guid of the cut plane """ # initialise length as 0 length = 0 # convert plane to a surface plane_surf = rs.AddPlanarSrf(cut_plane) # loop through the fractures' GUIDs for i in range(len(fracture_guid_list)): # perform intersection test intersection = rs.IntersectBreps(fracture_guid_list[i], plane_surf) # if there is intersection if intersection is not None: # go through the list for x in intersection: # check it's a line! if rs.IsLine(intersection[0]): # add the GUID to class attribute # 'intersecting_fractures' self.intersecting_fractures.append(intersection[0]) # increment the length of intersecting fractures length += rs.CurveLength(intersection[0]) # delete the plane surface we added to Rhino interface rs.DeleteObject(plane_surf) # return the lotal lengths of intersection return length
def initSlice(self, init_geo): result = [] plane = rs.PlaneFromPoints((-5000, -5000, 0), (0, -5000, 0), (-5000, 0, 0)) planeSrf = rs.AddPlaneSurface(plane, 10000, 10000) crv = rs.IntersectBreps(init_geo, planeSrf) result.append(crv) while True: vec = rs.CreateVector((0, 0, self.layer_height)) planeSrf = rs.MoveObject(planeSrf, vec) crv = rs.IntersectBreps(init_geo, planeSrf) if crv == None: break else: result.append(crv) result = rs.JoinCurves(result) for i in range(1, len(result)): if not rs.CurveDirectionsMatch(result[0], result[i]): rs.ReverseCurve(result[i]) return result
def cutAtPlan(level, join): cutPlane = rs.AddPlaneSurface([-1000,-1000,level], 3000, 3000) plane = rs.PlaneFromNormal([-1000,-1000,0], [0,0,1]) planPlane = rs.AddPlaneSurface(plane, 3000, 3000) objs = rs.VisibleObjects() intersectCrvs = [] tempCrv = None for obj in objs: if rs.IsBrep(obj): tempCrv = rs.IntersectBreps(obj, cutPlane) if tempCrv: rs.MatchObjectAttributes(tempCrv, obj) newCrvs = flatten(tempCrv) rs.DeleteObject(cutPlane) rs.DeleteObject(planPlane)
def CutSect(SurfaceId, SpanStation): # SpanStation is assumed to be along the y direction, in the range [0,1] (Xmin, Ymin, Zmin, Xmax, Ymax, Zmax) = ObjectsExtents(SurfaceId) YStation = Ymin + (Ymax - Ymin) * SpanStation OriginX = Xmin - 1 OriginZ = Zmin - 1 CutPlane = rs.PlaneFromPoints((OriginX, YStation, OriginZ), (Xmax + 1, YStation, OriginZ), (OriginX, YStation, Zmax + 1)) CutPlaneSrf = rs.AddPlaneSurface( CutPlane, max([(Xmax - Xmin), (Ymax - Ymin), (Zmax - Zmin)]) + 1, max([(Xmax - Xmin), (Ymax - Ymin), (Zmax - Zmin)]) + 1) I = rs.IntersectBreps(CutPlaneSrf, SurfaceId) Section = I[0] rs.DeleteObject(CutPlaneSrf) (Xmin, Ymin, Zmin, Xmax, Ymax, Zmax) = ObjectsExtents(Section) # Find the apparent chord of the section (that is, the line connecting the fore # most and aftmost points on the curve DivPoints = rs.DivideCurve(Section, 200) Xs = [] Ys = [] Zs = [] for DP in DivPoints: list.append(Xs, DP[0]) list.append(Ys, DP[1]) list.append(Zs, DP[2]) val, idx = min((val, idx) for (idx, val) in enumerate(Xs)) LeadingPoint = [Xs[idx], Ys[idx], Zs[idx]] val, idx = max((val, idx) for (idx, val) in enumerate(Xs)) TrailingPoint = [Xs[idx], Ys[idx], Zs[idx]] Chord = rs.AddLine(TrailingPoint, LeadingPoint) return Section, Chord
def contourPt(obj, pt): """ creates a contour according to xy plane at specified height obj: single object to contour pt: a point to contour at """ planPlane = rs.AddPlaneSurface([-10000, -10000, pt[2]], 30000, 30000) intersectCrvs = [] tempCrv = None if rs.IsBrep(obj): tempCrv = rs.IntersectBreps(obj, planPlane) if tempCrv != None: objName = rs.ObjectName(obj) rs.ObjectName(tempCrv, objName) intersectCrvs.append(tempCrv) rs.MatchObjectAttributes(tempCrv, obj) rs.DeleteObject(planPlane) return intersectCrvs
def overlap_length(tim_number, instance_pop): ''' :param tim_number: 1つの個体に使用する木材の本数 :param instance_pop: Generate クラスインスタンス :return: surface同士のintersection部のcurveの長さの合計値。 ''' cur_length = 0 for i in range(tim_number): tim1_srf = instance_pop.used_list[i].surface for j in range(tim_number): if i != j: tim2_srf = instance_pop.used_list[j].surface flag = rs.IntersectBreps(tim1_srf, tim2_srf) if flag is None: continue else: for k in range(len(flag)): cur_length = cur_length + rs.CurveLength(flag[k]) return cur_length
def find_neighbor_intersections(array, partIndex): """Given an array of srfs. find all intersections with a given srf. Return a list of tuples with neighbor index and crvs. representing intersections""" intersections = [] numItems = len(array) if partIndex >= numItems: return "part index outside of array" part = array[partIndex] #only searches neighbors indexed higher in the array for i in range(partIndex, numItems): neighbor = array[i] intersectionTest = rs.IntersectBreps(part, neighbor) if intersectionTest != None: intersections.append((i, intersectionTest)) # if there are no intersections alert the user if len(intersections) == 0: return "this part does not intersect with its neighbors" else: return intersections
def overlap_num(tim_number, instance_pop): # Evaluate the Intersection number -----> type is int intersect_num = 0 for i in range(tim_number): tim = instance_pop.used_list[i].surface for j in range(tim_number): if j == i: continue else: tim_other = instance_pop.used_list[j].surface flag = rs.IntersectBreps(tim, tim_other) if flag is None: continue if rs.IsCurve(flag[0]): intersect_num = intersect_num + 1 for k in range(len(flag)): rs.DeleteObject(flag[k]) return intersect_num
def LengthOfIntersection(self, fracture_guid_list): """ returns the sum of all length of intersections and helps to track the number of fracture intersections. Parameters ---------- fracture_guid_list: list a list of fractures' guids in the network """ # initialise length as 0 length = 0 # loop through all the fractures in the list for i in range(len(fracture_guid_list)): # fracture to test intersection against curveA = fracture_guid_list[i] # loop through all other fractures for j in range(len(fracture_guid_list)): # except the fractures we are testing against if j != i: # test for intersection intersection = rs.IntersectBreps(curveA, fracture_guid_list[j]) # if there is intersection if intersection is not None: for x in intersection: # check it's a line! if rs.IsLine(intersection[0]): # increase no of fracture intersections self.no_of_fracture_intersections += 1 # find the length of intersection self.lengths_of_intersection_lines.append( rs.CurveLength(intersection[0])) # increment the length length += rs.CurveLength(intersection[0]) # continue if i == j else: continue return length
def slice(self): ''' 1. intersect with sliceSurface and additiveObj 2. make shells(outline) from each intersected line [3-1. if bottom, make layer fill from intersected line] [3-2. if not bottom, make layer infill] ''' layer = 0 while True: tmpText = "\n" + "; layer " + str(layer) + "\n" + "\n" + "\n" #tmpText += "G92 E0\n" self.gcoder.addGcode(tmpText) self.gcoder.initEValue() sliceSurface = rs.CopyObject( self.contactSurface, (0, 0, self.gcoder.getLayerHeight() * layer)) #make intersected lines intersectedLines = rs.IntersectBreps(sliceSurface, self.additiveObj) if intersectedLines is None: #slice is done rs.DeleteObject(sliceSurface) print('slicing is done') return True #delete unClosed Line from intersectedLines cullIndex = [] openCurves = [] for i in range(len(intersectedLines)): if not rs.IsCurveClosed(intersectedLines[i]): cullIndex.append(i) for i in range(len(cullIndex)): cullIndex[i] -= i for i in cullIndex: #rs.DeleteObject(intersectedLines[i]) openCurves.append(intersectedLines[i]) del intersectedLines[i] if layer == 0: self.travelStartPoint = (0, 0, 200) #make shell from outline for outline in intersectedLines: ##debug needs #tmpText = "G1 Z45 F3600\n" #self.gcoder.addGcode(tmpText) prePoint = None currentPoint = None convertedPolyline = rs.ConvertCurveToPolyline(outline) vertices = rs.CurveEditPoints(convertedPolyline) rs.DeleteObject(convertedPolyline) flag = True for ver in vertices: currentPoint = ver if flag: if self.travelStartPoint is None: print('travelStartPoint is None') if currentPoint is None: print('currentPoint is None') travelResult = self.travel(self.travelStartPoint, currentPoint, sliceSurface) if travelResult is False: tmpText = "G92 E0\nG1 E-2 F3600\n" tmpText += "G1 Z{0}\n".format(currentPoint[2] + 10) tmpText += "G1 X{0} Y{1} Z{2}\n".format( currentPoint[0], currentPoint[1], currentPoint[2]) tmpText += "G1 E0\n" self.gcoder.addGcode(tmpText) flag = False ##traveling end else: self.gcoder.calcEValue( rs.Distance(currentPoint, prePoint)) tmpText = "G1 X{0} Y{1} Z{2} E{3} F{4}\n".format( currentPoint[0], currentPoint[1], currentPoint[2], self.gcoder.getEValue(), 1800) ##We don't need to use outer shell for BiMatrix, so I commented out the next line. ##self.gcoder.addGcode(tmpText) ## prePoint = currentPoint else: self.travelStartPoint = currentPoint self.setLayerFillT0(outline, layer) self.setLayerFillT1(outline, layer) ''' for openCurve in openCurves: #self.gcoder.addGcode("G1 Z45 F3600\n") prePoint = None currentPoint = None convertedPolyline = rs.ConvertCurveToPolyline(openCurve) vertices = rs.CurveEditPoints(convertedPolyline) rs.DeleteObject(convertedPolyline) flag = True for ver in vertices: currentPoint = ver if flag: tmpText = "G1 X{0} Y{1} Z{2} F{3}\n".format(currentPoint[0], currentPoint[1], currentPoint[2], 3600) flag = False else: self.gcoder.calcEValue(rs.Distance(currentPoint, prePoint)) tmpText = "G1 X{0} Y{1} Z{2} E{3} F{4}\n".format(currentPoint[0], currentPoint[1], currentPoint[2], self.gcoder.getEValue(), 1800) prePoint = currentPoint self.gcoder.addGcode(tmpText) ''' ##for zuhan #rs.DeleteObjects(intersectedLines) rs.DeleteObjects(openCurves) #make layer fill #make layer infil rs.DeleteObject(sliceSurface) layer += 1 return True
#add random xnum,ynum, or znum to respective index newboxArray = rs.AddBox([(newPtCoord),(newPtCoord[0]+xnum,newPtCoord[1],newPtCoord[2]),\ (newPtCoord[0]+xnum,newPtCoord[1]+ynum,newPtCoord[2]),(newPtCoord[0],newPtCoord[1]+ynum,newPtCoord[2]),\ (newPtCoord[0],newPtCoord[1],newPtCoord[2]+znum),(newPtCoord[0]+xnum,newPtCoord[1],\ newPtCoord[2]+znum),(newPtCoord[0]+xnum,newPtCoord[1]+ynum,newPtCoord[2]+znum),\ (newPtCoord[0],newPtCoord[1]+ynum,newPtCoord[2]+znum)]) pts.append(newPt) boxes.append(newboxArray) #for each new box created, boolean difference the previous box #newObject = rs.BooleanIntersection(boxes[i-1],boxes[i],delete_input=False) if i == 1: intersectTrue = rs.IntersectBreps(boxes[i - 1], boxes[i]) if intersectTrue: newObject = rs.BooleanDifference(boxes[i - 1], boxes[i], delete_input=False) else: print "No Intersection" else: intersectTrue = rs.IntersectBreps(newObject, boxes[i]) if intersectTrue: newObject = rs.BooleanDifference(newObject, boxes[i], delete_input=False) else: print "nothing" #newObject = boxes[i]
def optimization(used_centerP, used_surfaceP, used_surface, unused_surface, unused_line, unused_poly, unused_mark_line, tolerance): start_time = time.time() vector = rs.VectorCreate(used_surfaceP, used_centerP) normal = rs.VectorUnitize(vector) vec_length = rs.VectorScale(normal, 0.01) vec_reverse = rs.VectorReverse(normal) vec_reverse = rs.VectorScale(vec_reverse, 0.1) # 描画 # AddVector(used_centerP, vector) # AddVector(used_centerP, vec_reverse) # 接触判定 for i in range(200): curve = rs.IntersectBreps(used_surface, unused_surface) if i == 199: # print("Can not Optimization tan1") if curve: for k in range(len(curve)): rs.DeleteObject(curve[k]) # run time console end_time = time.time() optimization_run_time = end_time - start_time # print("-------------------------------------------------------") # print("optimization Run time: %s" % optimization_run_time) return False # timberが接触していない場合 if curve is None: rs.MoveObject(unused_surface, vec_reverse) rs.MoveObject(unused_line, vec_reverse) rs.MoveObject(unused_poly, vec_reverse) rs.MoveObject(unused_mark_line[0], vec_reverse) rs.MoveObject(unused_mark_line[1], vec_reverse) # timberが接触している場合 else: length = 0 for j in range(0, len(curve)): if rs.IsCurve(curve[j]): length = length + rs.CurveLength(curve[j]) else: rs.MoveObject(unused_surface, vec_length) rs.MoveObject(unused_line, vec_length) rs.MoveObject(unused_poly, vec_length) rs.MoveObject(unused_mark_line[0], vec_length) rs.MoveObject(unused_mark_line[1], vec_length) continue # console # print("curve length[%s]: %s | vec length: %s" % (i, length, vec_length)) # 接合条件を満たした場合 if length < tolerance: # print("-------------------------------------------------------") # print("tan1 <count: %s | curve length: %s>" % (i, length)) # run time console end_time = time.time() optimization_run_time = end_time - start_time # print("optimization Run time: %s" % optimization_run_time) return curve # 接合条件を満たさない場合 else: rs.MoveObject(unused_surface, vec_length) rs.MoveObject(unused_line, vec_length) rs.MoveObject(unused_poly, vec_length) rs.MoveObject(unused_mark_line[0], vec_length) rs.MoveObject(unused_mark_line[1], vec_length) # オフセットする大きさを更新 if length < 45: vec_length = rs.VectorScale(normal, 0.05) elif length < 60: vec_length = rs.VectorScale(normal, 0.55) elif length < 80: vec_length = rs.VectorScale(normal, 0.75) elif length < 120: vec_length = rs.VectorScale(normal, 2.5) elif length < 200: vec_length = rs.VectorScale(normal, 3.5) else: vec_length = rs.VectorScale(normal, 8.0) # objectを削除 for k in range(0, len(curve)): rs.DeleteObject(curve[k]) if i == 199: # print("Can not Optimization tan1") if curve: for k in range(0, len(curve)): rs.DeleteObject(curve[k]) # run time console end_time = time.time() optimization_run_time = end_time - start_time # print("-------------------------------------------------------") # print("optimization Run time: %s" % optimization_run_time) return False
def optimization_bridge(_unused_srf, _unused_line, _unused_poly, _unused_mark_line, _used_srf1, _used_srf2, _rotate_point1, _rotate_point2, _rotate_axis1, _rotate_axis2, _move_vec1, _move_vec2, tolerance): start_time = time.time() unused_surface = _unused_srf unused_line = _unused_line unused_polyline = _unused_poly unused_mark_line = _unused_mark_line used_surface1 = _used_srf1 used_surface2 = _used_srf2 rotate_point1 = _rotate_point1 rotate_point2 = _rotate_point2 rotate_axis1 = _rotate_axis1 rotate_axis2 = _rotate_axis2 angle1 = -0.01 angle2 = -0.01 move_vec1 = _move_vec1 move_vec2 = _move_vec2 normal1 = rs.VectorUnitize(move_vec1) normal2 = rs.VectorUnitize(move_vec2) vec_length1 = rs.VectorScale(normal1, 0.1) vec_length2 = rs.VectorScale(normal2, 0.1) vec_reverse1 = rs.VectorReverse(vec_length1) vec_reverse2 = rs.VectorReverse(vec_length2) curve_length1 = [] curve_length2 = [] count1 = 0 count2 = 0 # 衝突判定 for i in range(200): curve1 = rs.IntersectBreps(used_surface1, unused_surface) curve2 = rs.IntersectBreps(used_surface2, unused_surface) # 最適化できなかった場合 if i == 199: # print("-------------------------------------------------------") # print("Can not Optimization bridge") # run time console end_time = time.time() optimization_bridge_run_time = end_time - start_time # print("---------------------------------------------------") # print("optimization_bridge Run time: %s" % optimization_bridge_run_time) return False # 接点1でも接点2でも接していない時 if curve1 is None and curve2 is None: rs.MoveObject(unused_surface, vec_length1) rs.MoveObject(unused_line, vec_length1) rs.MoveObject(unused_polyline, vec_length1) rs.MoveObject(unused_mark_line[0], vec_length1) rs.MoveObject(unused_mark_line[1], vec_length1) continue # 接点2では接しているが接点1では接していない時 if curve1 is None: # rs.MoveObject(unused_surface, vec_reverse) # rs.MoveObject(unused_line, vec_reverse) # rs.MoveObject(unused_poly, vec_reverse) rs.RotateObject(unused_surface, rotate_point2, angle1, rotate_axis2) rs.RotateObject(unused_line, rotate_point2, angle1, rotate_axis2) rs.RotateObject(unused_polyline, rotate_point2, angle1, rotate_axis2) rs.RotateObject(unused_mark_line[0], rotate_point2, angle1, rotate_axis2) rs.RotateObject(unused_mark_line[1], rotate_point2, angle1, rotate_axis2) if curve2: for k in range(0, len(curve2)): rs.DeleteObject(curve2[k]) count1 = count1 + 1 # もし5回連続で接触しない場合、回転方向を逆転する if count1 == 5: angle1 = angle1 * -1.0 angle = 5.0 * angle1 rs.RotateObject(unused_surface, rotate_point2, angle, rotate_axis2) rs.RotateObject(unused_line, rotate_point2, angle, rotate_axis2) rs.RotateObject(unused_polyline, rotate_point2, angle, rotate_axis2) rs.RotateObject(unused_mark_line[0], rotate_point2, angle, rotate_axis2) rs.RotateObject(unused_mark_line[1], rotate_point2, angle, rotate_axis2) continue # 接点1では接しているが接点2では接していない時 if curve2 is None: # rs.MoveObject(unused_surface, vec_length) # rs.MoveObject(unused_line, vec_length) # rs.MoveObject(unused_poly, vec_length) rs.RotateObject(unused_surface, rotate_point1, angle2, rotate_axis1) rs.RotateObject(unused_line, rotate_point1, angle2, rotate_axis1) rs.RotateObject(unused_polyline, rotate_point1, angle2, rotate_axis1) rs.RotateObject(unused_mark_line[0], rotate_point1, angle2, rotate_axis1) rs.RotateObject(unused_mark_line[1], rotate_point1, angle2, rotate_axis1) if curve1: for k in range(0, len(curve1)): rs.DeleteObject(curve1[k]) count2 = count2 + 1 # もし5回連続で接触しない場合、回転方向を逆転する if count2 == 5: angle2 = angle2 * -1.0 angle = 5.0 * angle2 rs.RotateObject(unused_surface, rotate_point1, angle, rotate_axis1) rs.RotateObject(unused_line, rotate_point1, angle, rotate_axis1) rs.RotateObject(unused_polyline, rotate_point1, angle, rotate_axis1) rs.RotateObject(unused_mark_line[0], rotate_point1, angle, rotate_axis1) rs.RotateObject(unused_mark_line[1], rotate_point1, angle, rotate_axis1) continue # どちらも接触している場合 length1 = 0 length2 = 0 for j in range(0, len(curve1)): if rs.IsCurve(curve1[j]): length1 = length1 + rs.CurveLength(curve1[j]) else: rs.RotateObject(unused_surface, rotate_point1, angle2, rotate_axis1) rs.RotateObject(unused_line, rotate_point1, angle2, rotate_axis1) rs.RotateObject(unused_polyline, rotate_point1, angle2, rotate_axis1) rs.RotateObject(unused_mark_line[0], rotate_point1, angle2, rotate_axis1) rs.RotateObject(unused_mark_line[1], rotate_point1, angle2, rotate_axis1) continue for j in range(0, len(curve2)): if rs.IsCurve(curve2[j]): length2 = length2 + rs.CurveLength(curve2[j]) else: rs.RotateObject(unused_surface, rotate_point1, angle2, rotate_axis1) rs.RotateObject(unused_line, rotate_point1, angle2, rotate_axis1) rs.RotateObject(unused_polyline, rotate_point1, angle2, rotate_axis1) rs.RotateObject(unused_mark_line[0], rotate_point1, angle2, rotate_axis1) rs.RotateObject(unused_mark_line[1], rotate_point1, angle2, rotate_axis1) continue # 接点1でも接点2でも許容値の制約を満たすとき if length1 < tolerance and length2 < tolerance: # print("-------------------------------------------------------") # print("Final tan1 <count: %s | curve length1: %s>" % (i, length1)) # print("Final tan2 <count: %s | curve_length2: %s>" % (i, length2)) # run time console end_time = time.time() optimization_bridge_run_time = end_time - start_time # print("optimization_bridge Run time: %s" % optimization_bridge_run_time) return curve1, curve2 # 接点1で許容値の制約を満たすとき(接点2では満たさない) elif length1 < tolerance: # angleを更新 if length2 < 50: if angle2 > 0: angle2 = 0.01 else: angle2 = -0.01 elif length2 < 60: if angle2 > 0: angle2 = 0.04 else: angle2 = -0.04 elif length2 < 90: if angle2 > 0: angle2 = 0.07 else: angle2 = -0.07 elif length2 < 120: if angle2 > 0: angle2 = 0.15 else: angle2 = -0.15 elif length2 < 150: if angle2 > 0: angle2 = 0.35 else: angle2 = -0.35 else: if angle2 > 0: angle2 = 4.3 else: angle2 = -4.3 rs.RotateObject(unused_surface, rotate_point1, angle2, rotate_axis1) rs.RotateObject(unused_line, rotate_point1, angle2, rotate_axis1) rs.RotateObject(unused_polyline, rotate_point1, angle2, rotate_axis1) rs.RotateObject(unused_mark_line[0], rotate_point1, angle2, rotate_axis1) rs.RotateObject(unused_mark_line[1], rotate_point1, angle2, rotate_axis1) # print("length1[%s]: %s | angle2: %s" % (i, length1, angle2)) # print("length2[%s]: %s | angle2: %s" % (i, length2, angle2)) # 接点2の接触部の長さを格納する curve_length2.append(length2) # もし衝突交線の値が大きくなる場合、回転の方向を逆転する if len(curve_length2) == 3: if curve_length2[0] < curve_length2[1] < curve_length2[2]: angle2 = angle2 * -1.0 # print("update angle2") # print("angle2: %s" % angle2) angle = 3.0 * angle2 rs.RotateObject(unused_surface, rotate_point1, angle, rotate_axis1) rs.RotateObject(unused_line, rotate_point1, angle, rotate_axis1) rs.RotateObject(unused_polyline, rotate_point1, angle, rotate_axis1) rs.RotateObject(unused_mark_line[0], rotate_point1, angle, rotate_axis1) rs.RotateObject(unused_mark_line[1], rotate_point1, angle, rotate_axis1) curve_length2 = [] if curve1: for k in range(0, len(curve1)): rs.DeleteObject(curve1[k]) if curve2: for k in range(0, len(curve2)): rs.DeleteObject(curve2[k]) if i == 199: # print("-------------------------------------------------------") # print("Can not Optimization bridge") # run time console end_time = time.time() optimization_bridge_run_time = end_time - start_time # print("optimization_bridge Run time: %s" % optimization_bridge_run_time) return False # 接点2で許容値の制約を満たすとき(接点1では満たさない) elif length2 < tolerance: # angleを更新 if length1 < 45: if angle1 > 0: angle1 = 0.01 else: angle1 = -0.01 elif length1 < 60: if angle1 > 0: angle1 = 0.04 else: angle1 = -0.04 elif length1 < 90: if angle1 > 0: angle1 = 0.07 else: angle1 = -0.07 elif length1 < 120: if angle1 > 0: angle1 = 0.15 else: angle1 = -0.15 elif length1 < 150: if angle1 > 0: angle1 = 0.35 else: angle1 = -0.35 else: if angle1 > 0: angle1 = 4.3 else: angle1 = -4.3 rs.RotateObject(unused_surface, rotate_point2, angle1, rotate_axis2) rs.RotateObject(unused_line, rotate_point2, angle1, rotate_axis2) rs.RotateObject(unused_polyline, rotate_point2, angle1, rotate_axis2) rs.RotateObject(unused_mark_line[0], rotate_point2, angle1, rotate_axis2) rs.RotateObject(unused_mark_line[1], rotate_point2, angle1, rotate_axis2) # console # print("length1[%s]: %s | angle1: %s" % (i, length1, angle1)) # print("length2[%s]: %s | angle1: %s" % (i, length2, angle1)) # checkしているよ TODO # if length2 < 10: # rs.MoveObject(unused_surface, vec_reverse) # rs.MoveObject(unused_line, vec_reverse) # rs.MoveObject(unused_poly, vec_reverse) # 接点1の接触部の長さを格納する curve_length1.append(length1) # もし衝突交線の値が大きくなる場合、回転の方向を逆転する if len(curve_length1) == 3: if curve_length1[0] < curve_length1[1] < curve_length1[2]: angle1 = angle1 * -1.0 # print("update angle1") # print("angle1: %s" % angle1) angle = 3.0 * angle1 rs.RotateObject(unused_surface, rotate_point2, angle, rotate_axis2) rs.RotateObject(unused_line, rotate_point2, angle, rotate_axis2) rs.RotateObject(unused_polyline, rotate_point2, angle, rotate_axis2) rs.RotateObject(unused_mark_line[0], rotate_point2, angle, rotate_axis2) rs.RotateObject(unused_mark_line[1], rotate_point2, angle, rotate_axis2) curve_length1 = [] if curve1: for k in range(0, len(curve1)): rs.DeleteObject(curve1[k]) if curve2: for k in range(0, len(curve2)): rs.DeleteObject(curve2[k]) if i == 199: # print("-------------------------------------------------------") # print("Can not Optimization bridge") # run time console end_time = time.time() optimization_bridge_run_time = end_time - start_time # print("optimization_bridge Run time: %s" % optimization_bridge_run_time) return False else: rs.MoveObject(unused_surface, vec_reverse1) rs.MoveObject(unused_line, vec_reverse1) rs.MoveObject(unused_polyline, vec_reverse1) rs.MoveObject(unused_mark_line[0], vec_reverse1) rs.MoveObject(unused_mark_line[1], vec_reverse1) if curve1: for k in range(0, len(curve1)): rs.DeleteObject(curve1[k]) if curve2: for k in range(0, len(curve2)): rs.DeleteObject(curve2[k]) if i == 199: # print("-------------------------------------------------------") # print("Can not Optimization bridge") # run time console end_time = time.time() optimization_bridge_run_time = end_time - start_time # print("optimization_bridge Run time: %s" % optimization_bridge_run_time) return False
def optimization_rotate(_origin_point, _x_point, _y_point, _unused_srf, _unused_line, _unused_polyline, _unused_mark_line, _used_srf1, unused_timber, tolerance): start_time = time.time() # 初期変数 origin_point = _origin_point x_point = _x_point y_point = _y_point unused_srf = _unused_srf unused_line = _unused_line unused_polyline = _unused_polyline unused_mark_line = _unused_mark_line used_srf1 = _used_srf1 angle1 = 0.1 angle2 = -0.03 curve_length = [] count1 = 0 angle2_flag = False end_joint_count = 0 # 回転平面を定義する new_plane = rs.PlaneFromPoints(origin_point, x_point, y_point) rs.ViewCPlane(None, new_plane) rotate_p = origin_point vec1 = rs.VectorCreate(x_point, rotate_p) vec2 = rs.VectorCreate(y_point, rotate_p) cross = rs.VectorCrossProduct(vec1, vec2) cross_unit = rs.VectorUnitize(cross) rotate_vec = rs.VectorScale(cross_unit, 100) # 描画 # rotate_axis = AddVector(rotate_p, rotate_vec) # print("-------------------------------------------------------") # 衝突判定 for i in range(200): curve = rs.IntersectBreps(unused_srf, used_srf1) # もし接触しなかった場合 if curve is None: curve_length = [] if i == 0: angle2_flag = True angle2 = -1.0 if i == 1: angle = (angle1 * -1.1) rs.RotateObject(unused_srf, rotate_p, angle, rotate_vec) rs.RotateObject(unused_line, rotate_p, angle, rotate_vec) rs.RotateObject(unused_polyline, rotate_p, angle, rotate_vec) rs.RotateObject(unused_mark_line[0], rotate_p, angle, rotate_vec) rs.RotateObject(unused_mark_line[1], rotate_p, angle, rotate_vec) if i == 199: print("tan2: Can not optimize") # input("Can not optimize") # object削除 if curve: for k in range(0, len(curve)): rs.DeleteObject(curve[k]) # 平面をもとのxy平面に戻す origin_point = (0, 0, 0) x_point = (100, 0, 0) y_point = (0, 100, 0) new_plane = rs.PlaneFromPoints(origin_point, x_point, y_point) rs.ViewCPlane(None, new_plane) # run time console end_time = time.time() optimization_rotate_run_time = end_time - start_time # print("---------------------------------------------------") # print("optimization_rotate Run time: %s" % optimization_rotate_run_time) return False # console # print("There is not curve[%s] angle2: %s" % (i, angle2)) rs.RotateObject(unused_srf, rotate_p, angle2, rotate_vec) rs.RotateObject(unused_line, rotate_p, angle2, rotate_vec) rs.RotateObject(unused_polyline, rotate_p, angle2, rotate_vec) rs.RotateObject(unused_mark_line[0], rotate_p, angle2, rotate_vec) rs.RotateObject(unused_mark_line[1], rotate_p, angle2, rotate_vec) count1 = count1 + 1 # もし20回連続で接触しない場合、回転方向を逆転する if count1 == 10 and angle2_flag: angle2 = angle2 * -1.0 angle = 10 * angle2 rs.RotateObject(unused_srf, rotate_p, angle, rotate_vec) rs.RotateObject(unused_line, rotate_p, angle, rotate_vec) rs.RotateObject(unused_polyline, rotate_p, angle, rotate_vec) rs.RotateObject(unused_mark_line[0], rotate_p, angle, rotate_vec) rs.RotateObject(unused_mark_line[1], rotate_p, angle, rotate_vec) angle2_flag = False continue # もし接触した場合 else: length = 0 for j in range(0, len(curve)): if rs.IsCurve(curve[j]): length = length + rs.CurveLength(curve[j]) else: rs.RotateObject(unused_srf, rotate_p, angle1, rotate_vec) rs.RotateObject(unused_line, rotate_p, angle1, rotate_vec) rs.RotateObject(unused_polyline, rotate_p, angle1, rotate_vec) rs.RotateObject(unused_mark_line[0], rotate_p, angle1, rotate_vec) rs.RotateObject(unused_mark_line[1], rotate_p, angle1, rotate_vec) continue # 接点2の接触部の長さを格納する curve_length.append(length) # もし衝突交線の値が大きくなる場合、回転の方向を逆転する if len(curve_length) == 5: if curve_length[0] < curve_length[1] < curve_length[ 2] < curve_length[3] < curve_length[4]: angle1 = angle1 * -1.0 # print("update angle1") # print("angle1: %s" % angle1) angle = 3.0 * angle1 rs.RotateObject(unused_srf, rotate_p, angle, rotate_vec) rs.RotateObject(unused_line, rotate_p, angle, rotate_vec) rs.RotateObject(unused_polyline, rotate_p, angle, rotate_vec) rs.RotateObject(unused_mark_line[0], rotate_p, angle, rotate_vec) rs.RotateObject(unused_mark_line[1], rotate_p, angle, rotate_vec) curve_length = [] # 接合条件を満たした場合 if length < tolerance: select_curve = curve[0] reference_point = createMidPointFromCurve(select_curve) check_domain = unused_timber.judgeSurfaceDomain( reference_point) # もし接触部が端部(domainが0か8の時) if check_domain == 0 or check_domain == 8: rs.RotateObject(unused_srf, rotate_p, angle1, rotate_vec) rs.RotateObject(unused_line, rotate_p, angle1, rotate_vec) rs.RotateObject(unused_polyline, rotate_p, angle1, rotate_vec) rs.RotateObject(unused_mark_line[0], rotate_p, angle1, rotate_vec) rs.RotateObject(unused_mark_line[1], rotate_p, angle1, rotate_vec) end_joint_count = end_joint_count + 1 if end_joint_count == 2: # print("tan2: Can not optimize(joint is ends)") # run time console end_time = time.time() optimization_rotate_run_time = end_time - start_time # print("---------------------------------------------------") # print("optimization_rotate Run time: %s" % optimization_rotate_run_time) return False continue else: # print("tan2 <count: %s | curve_length = %s>" % (i, length)) # 平面をもとのxy平面に戻す origin_point = (0, 0, 0) x_point = (100, 0, 0) y_point = (0, 100, 0) new_plane = rs.PlaneFromPoints(origin_point, x_point, y_point) rs.ViewCPlane(None, new_plane) # run time console end_time = time.time() optimization_rotate_run_time = end_time - start_time # print("optimization_rotate Run time: %s" % optimization_rotate_run_time) return curve # 接合条件を満たさなかった場合 else: # angleを更新 if length < 45: if angle1 > 0: angle1 = 0.05 else: angle1 = -0.05 elif length < 60: if angle1 > 0: angle1 = 0.25 else: angle1 = -0.25 elif length < 70: if angle1 > 0: angle1 = 0.35 else: angle1 = -0.35 elif length < 100: if angle1 > 0: angle1 = 0.65 else: angle1 = -0.65 elif length < 120: if angle1 > 0: angle1 = 1.75 else: angle1 = -1.75 else: if angle1 > 0: angle1 = 2.0 else: angle1 = -2.0 rs.RotateObject(unused_srf, rotate_p, angle1, rotate_vec) rs.RotateObject(unused_line, rotate_p, angle1, rotate_vec) rs.RotateObject(unused_polyline, rotate_p, angle1, rotate_vec) rs.RotateObject(unused_mark_line[0], rotate_p, angle1, rotate_vec) rs.RotateObject(unused_mark_line[1], rotate_p, angle1, rotate_vec) # print("curve length[%s]: %s | angle1: %s" % (i, length, angle1)) # object削除 for k in range(0, len(curve)): rs.DeleteObject(curve[k]) if i == 199: # print("tan2: Can not optimize") if curve: for k in range(0, len(curve)): rs.DeleteObject(curve[k]) # 平面をもとのxy平面に戻す origin_point = (0, 0, 0) x_point = (100, 0, 0) y_point = (0, 100, 0) new_plane = rs.PlaneFromPoints(origin_point, x_point, y_point) rs.ViewCPlane(None, new_plane) # run time console end_time = time.time() optimization_rotate_run_time = end_time - start_time # print("---------------------------------------------------") # print("optimization_rotate Run time: %s" % optimization_rotate_run_time) return False
def slice(self): print("Slicing starts") print("It may take a long time") deleteItem = [] fileN = rs.SaveFileName( "Output file", "G-Code Files (*.gcode)|*.gcode|All Files (*.*)|*.*|") self.gcoder.initGcode(fileN) tmpText = "" #layer by layer layer = 0 for layer in range( int(self.distancePrinting / self.fixedLayerHeight) + 1): tmpText = "; layer " + str(layer) + "\n" #init evalue tmpText += "G92 E0\n" self.gcoder.addGcode(tmpText) self.gcoder.initEValue() nextVec = (0, 0, float(self.fixedLayerHeight * layer)) slicer = rs.CopyObject(self.sliceSurface, nextVec) slicedCurves = rs.IntersectBreps(self.addtiveObj, slicer) #deleteItem.append(slicedCurves) rs.DeleteObject(slicer) if slicedCurves == None: continue ''' if slicedCurves == None: print('slicing done') self.gcoder.finishGcode() fileN = rs.SaveFileName("Output file", "G-Code Files (*.gcode)|*.gcode|All Files (*.*)|*.*|", None, None) self.gcoder.outputFile(fileN) return ''' #slicedCurve one by one for slicedCurve in slicedCurves: if rs.IsCurve(slicedCurve) is False: continue if slicedCurve is None: break self.makeGcodeFromSlicedCurve(slicedCurve, layer) rs.DeleteObjects(slicedCurves) print('slicing done') self.gcoder.finishGcode() #fileN = rs.SaveFileName("Output file", "G-Code Files (*.gcode)|*.gcode|All Files (*.*)|*.*|") self.gcoder.outputFile() return True
def slice(self): print("Slicing starts") print("It may take a long time") deleteItem = [] self.gcoder.initGcode() tmpText = "" multiplier = float(self.gcoder.getLayerHeight() * math.cos(math.radians(self.angleOfSurface))) print('multiplier') print(multiplier) #layer by layer layer = 0 for layer in range(int(self.distancePrinting / multiplier) + 1): #while(True): tmpText = "; layer " + str(layer) + "\n" #init evalue tmpText += "G92 E0\n" self.gcoder.addGcode(tmpText) self.gcoder.initEValue() nextVec = (0, 0, float(multiplier * layer)) slicer = rs.CopyObject(self.sliceSurface, nextVec) slicedCurves = rs.IntersectBreps(self.addtiveObj, slicer) #deleteItem.append(slicedCurves) rs.DeleteObject(slicer) if slicedCurves == None: print('slicing done') self.gcoder.finishGcode() fileN = rs.SaveFileName( "Output file", "G-Code Files (*.gcode)|*.gcode|All Files (*.*)|*.*|", None, self.fileName) self.gcoder.outputFile() return #slicedCurve one by one for slicedCurve in slicedCurves: self.makeGcodeFromSlicedCurve(slicedCurve, layer, nextVec, multiplier) layer += 1 rs.DeleteObjects(slicedCurves) self.gcoder.finishGcode() fileN = rs.SaveFileName( "Output file", "G-Code Files (*.gcode)|*.gcode|All Files (*.*)|*.*|") self.gcoder.outputFile(fileN) return True
lineaire = x, y, z # Intersection des perp frame de l'axe avec la surface DomAxe = [] DomAxe = rs.CurveDomain(Axe) OrigineAxe = rs.EvaluateCurve(Axe, DomAxe[0]) cutplane = rs.CurvePerpFrame(Axe, DomAxe[0]) clength = [] if cutplane: planesrf = rs.AddPlaneSurface(cutplane, 100, 100) curves = rs.IntersectBreps(srf, planesrf) rs.DeleteObject(planesrf) clength = rs.CurveLength(curves) #Best Candidate bat_Util = [] for j in range(len(z) - 1): bat_Util.append(0) for k in range(len(z) - 1): ind = 0 BDiff = 10 IsMatching = False if bat_Util[k] == 0: if z[k] > clength:
def collisionDetectionTolerance(used_timber_list, not_used_timber_list, unused_timber, id_connect, tolerance=250): num_used_timber = len(used_timber_list) num_not_used_timber = len(not_used_timber_list) sum_timber = num_used_timber + num_not_used_timber timber1 = unused_timber # これから生成するTimber count = 0 # timber1と他のused_timberが衝突していない時のカウント # 衝突判定(unused_timberとused_listのtimber同士の接触判定) for i in range(num_used_timber): # 接合部は衝突とみなさない if i == id_connect: count = count + 1 # 接合部材以外のused_timberとの衝突判定 else: timber2 = used_timber_list[i] curve = rs.IntersectBreps(timber1.surface, timber2.surface) # 衝突していない場合 if curve is None: count = count + 1 # 衝突している場合 else: length = 0 for j in range(len(curve)): length = length + rs.CurveLength(curve[j]) if length < tolerance: # 他の材との接触が許容範囲内であるならばOK count = count + 1 # print("permitted the intersection : intersection curve length : %s " % (length)) #--------------------------------------------------------------------------------------------------- # ここに接触時のロボットアームによる切削加工経路生成プログラム、または必要情報生成のプログラムを加える。 #--------------------------------------------------------------------------------------------------- else: for k in range(len(curve)): rs.DeleteObject(curve[k]) break # 衝突部に目印の球体を生成 --> ただの目印なので接触処理するときはコメントアウトしてもらえればと # mark_sphere = createMarkSphere(curve) # rs.ObjectLayer(mark_sphere, "collision") # 衝突判定(unused_timberとnot_used_listのtimber同士の接触判定) for j in range(num_not_used_timber): timber2 = not_used_timber_list[j] curve = rs.IntersectBreps(timber1.surface, timber2.surface) # 衝突していない場合 if curve is None: count = count + 1 # 衝突している場合 else: length = 0 for j in range(len(curve)): length = length + rs.CurveLength(curve[j]) if length < tolerance: # 他の材との接触が許容範囲内であるならばOK count = count + 1 # print("permitted the intersection : intersection curve length : %s "%(length) ) # --------------------------------------------------------------------------------------------------- # ここに接触時のロボットアームによる切削加工経路生成プログラム、または必要情報生成のプログラムを加える。 # --------------------------------------------------------------------------------------------------- else: for k in range(len(curve)): rs.DeleteObject(curve[k]) break # 衝突部に目印の球体を生成 --> ただの目印なので接触処理するときはコメントアウトしてもらえればと # mark_sphere = createMarkSphere(curve) # rs.ObjectLayer(mark_sphere, "collision") # unused_timberがどの部材とも衝突してない場合 if count == sum_timber: return False # unused_timberがいずれかの部材と衝突している場合 else: return True
#Array line if line: i = 0 for i in range(array_number): offset_x = distance_x * i line_copy = (offset_x, 0, 0) array_lines.append(rs.CopyObject( line, line_copy )) n = 0 for n in range(array_z_number): offset_z = Layerheight * n surface_copy = (0,0,offset_z) array_surface = rs.CopyObject(surface ,surface_copy) intersect_crv = rs.IntersectBreps(obj, array_surface) if intersect_crv is None: break intersect_srf = rs.AddPlanarSrf(intersect_crv) if intersect_srf is None: break rs.DeleteObjects(intersect_crv) rs.DeleteObjects(array_surface) # Project down
def IntersectionMatrix(self, boundary_list, domain_fractures): """ method to create a square intersection matrix for fracture-fracture and fracture-boundary intersections. Returns the matrix. Parameters ---------- boundary_list: list list of boundary guids domain_fractures: list list of fractures guids contained in the domain Raises ----- TypeError if the arguments are not of type list """ try: if type(boundary_list) != list or type(domain_fractures) != list: raise TypeError except TypeError: print("The two arguments should be of type list") else: # initialise a Matrix mat = [] # number of fractures num_frac = len(domain_fractures) # number of rows and cols for matrix n_row = num_frac + 6 n_col = num_frac + 6 # append to matrix for i in range(n_row): mat.append([]) for j in range(n_col): mat[i].append(j) mat[i][j] = 0 # boundary to bounday taken care by the matrix initialization # fractures to fractures for i in range(num_frac): for j in range(num_frac): if i != j: intersection = rs.IntersectBreps( domain_fractures[i], domain_fractures[j]) if intersection is not None: # set the matrix elements to be # length of intersection # since it is a symmetric matrix # mat[i][j] == mat[j][i] mat[i][j] = rs.CurveLength(intersection[0]) mat[j][i] = rs.CurveLength(intersection[0]) # boundary-fractures for i in range(num_frac): # 0 to number of fractures - 1 # number of fractures to end of row/col for j in range(num_frac, n_col): intersection = rs.IntersectBreps( domain_fractures[i], boundary_list[j - num_frac]) if intersection is not None: # set the matrix elements to be length of intersection # since it is a symmetric matrix mat[i][j] == mat[j][i] mat[i][j] = rs.CurveLength(intersection[0]) mat[j][i] = rs.CurveLength(intersection[0]) # return matrix return mat