def detectTouching(self): touch_edges=[] stationary_edges,sliding_edges=self.getAllEdges() for edge1 in stationary_edges: for edge2 in sliding_edges: inter=GeoFunc.intersection(edge1,edge2) if inter!=[]: pt=[inter[0],inter[1]] # 交叉点 edge1_bound=(GeoFunc.almostEqual(edge1[0],pt) or GeoFunc.almostEqual(edge1[1],pt)) # 是否为边界 edge2_bound=(GeoFunc.almostEqual(edge2[0],pt) or GeoFunc.almostEqual(edge2[1],pt)) # 是否为边界 stationary_start=GeoFunc.almostEqual(edge1[0],pt) # 是否开始 orbiting_start=GeoFunc.almostEqual(edge2[0],pt) # 是否开始 touch_edges.append({ "edge1":edge1, "edge2":edge2, "vector1":self.edgeToVector(edge1), "vector2":self.edgeToVector(edge2), "edge1_bound":edge1_bound, "edge2_bound":edge2_bound, "stationary_start":stationary_start, "orbiting_start":orbiting_start, "pt":[inter[0],inter[1]], "type":0 }) return touch_edges
def getBreakPoints(self,edge,slide_edge,_type): int_type=0 if _type=="vertical": int_type=1 # 两条直线四个组合计算 break_points=[] self.getSlideT(slide_edge[0],edge,int_type,1,break_points) self.getSlideT(slide_edge[1],edge,int_type,1,break_points) self.getSlideT(edge[0],slide_edge,int_type,-1,break_points) self.getSlideT(edge[1],slide_edge,int_type,-1,break_points) # 必须是有两个交点 if len(break_points)<2: return print(break_points) break_points=self.deleteDuplicated(break_points) # 开始计算具体参数 t1=min(break_points[0],break_points[1]) t2=max(break_points[0],break_points[1]) sliding_result1=GeoFunc.getSlideLine(slide_edge,t1,0) sliding_result2=GeoFunc.getSlideLine(slide_edge,t2,0) if _type=="vertical": sliding_result1=GeoFunc.getSlideLine(slide_edge,0,t1) sliding_result2=GeoFunc.getSlideLine(slide_edge,0,t2) pt1=GeoFunc.intersection(sliding_result1,edge) # 可能为Tuple pt2=GeoFunc.intersection(sliding_result2,edge) # 可能为Tuple pt3=self.getHoriVerInter(pt1,sliding_result2,int_type) ratio=(LineString([pt1,pt2]).length)/(t2-t1) # 两条边的比例 sin_theta=abs(pt1[1-int_type]-pt2[1-int_type])/(LineString([pt1,pt2]).length) # 直线与水平的角度 A1=0.5*ratio*sin_theta B1=-2*t1*A1 C1=t1*t1*A1 # 计算A2 B2 C2 A2=0 B2=abs(pt1[1-int_type]-pt2[1-int_type]) # 平行四边形的高度 C2=Polygon([pt1,pt2,pt3]).area-B2*t2 # 三角形面积 return [[t1,A1,B1,C1],[t2,0,B2,C2]]