def extendToFault(self , other_fault , k): polyline = self.getIJPolyline(k) p0 = polyline[-2] p1 = polyline[-1] ray_dir = GeometryTools.lineToRay( p0 , p1 ) intersections = GeometryTools.rayPolygonIntersections( p1 , ray_dir , other_fault.getIJPolyline(k)) if intersections: p2 = intersections[0][1] return [p1 , (int(p2[0]) , int(p2[1])) ] p0 = polyline[1] p1 = polyline[0] ray_dir = GeometryTools.lineToRay( p0 , p1 ) intersections = GeometryTools.rayPolygonIntersections( p1 , ray_dir , other_fault.getIJPolyline(k)) if intersections: if len(intersections) > 1: d_list = [ GeometryTools.distance( p1 , p[1] ) for p in intersections ] index = d_list.index( min(d_list) ) else: index = 0 p2 = intersections[index][1] return [p1 , (int(p2[0]) , int(p2[1])) ] raise ValueError("The fault %s can not be extended to intersect with:%s in layer:%d" % (self.getName() , other_fault.getName() , k+1 ))
def __rayIntersect(p0, p1 , polyline): ray_dir = GeometryTools.lineToRay( p0 , p1 ) intersections = GeometryTools.rayPolygonIntersections( p1 , ray_dir , polyline) if intersections: if len(intersections) > 1: d_list = [ GeometryTools.distance( p1 , p[1] ) for p in intersections ] index = d_list.index( min(d_list) ) else: index = 0 p2 = intersections[index][1] return [p1 , p2] else: return None
def extendToBBox(self , bbox , k , start = True): fault_polyline = self.getPolyline(k) if start: p0 = fault_polyline[1] p1 = fault_polyline[0] else: p0 = fault_polyline[-2] p1 = fault_polyline[-1] ray_dir = GeometryTools.lineToRay(p0,p1) intersections = GeometryTools.rayPolygonIntersections( p1 , ray_dir , bbox) if intersections: p2 = intersections[0][1] if self.getName(): name = "Extend:%s" % self.getName() else: name = None return CPolyline( name = name , init_points = [(p1[0] , p1[1]) , p2]) else: raise Exception("Logical error - must intersect with bounding box")