def get_inter_data_convexpolygon_convexpolygon( first_poly: "ConvexPolygon", second_poly: "ConvexPolygon") -> Optional[CollisionData]: penetration_length: float = 0.0 points: List[Vector2d] = [] # TODO delete the part if optimization is necessary for diagonal in first_poly.diagonals: diagonal_inter_data = get_inter_data_segment_convexpolygon( diagonal, second_poly) if diagonal_inter_data: penetration_length = diagonal_inter_data[1] for side in first_poly.sides: side_inter_data = get_inter_data_segment_convexpolygon( side, second_poly) if side_inter_data: points.extend(side_inter_data[0]) if penetration_length == 0.0: penetration_length = side_inter_data[1] if len(points) == 0: return None return CollisionData(points, penetration_length)
def get_inter_data_ellipse_circle(ellipse: "Ellipse", circle: "Circle") -> Optional[CollisionData]: data = get_inter_ellipse_ellipse(circle, ellipse, get_inter_data_segment_circle, get_inter_data_segment_ellipse) return CollisionData([data[1]], data[2])
def get_inter_data_ellipse_ellipse( first_ellipse: "Ellipse", second_ellipse: "Ellipse") -> Optional[CollisionData]: data = get_inter_ellipse_ellipse(first_ellipse, second_ellipse, get_inter_data_segment_ellipse, get_inter_data_segment_ellipse) return CollisionData([data[0]], data[2])
def get_inter_data_ray_ray(first_ray: "ray", second_ray: "Ray") -> Optional[CollisionData]: coefficients = get_penetr_ray_ray_coeff(first_ray, second_ray) if not coefficients: return None intersection_point = get_segments_intersection_points(first_ray, coefficients) return CollisionData(intersection_point)
def get_inter_data_line_ray(line: "Line", ray: "Ray") -> Optional[CollisionData]: coefficients = get_penetr_line_ray_coeff(line, ray) if not coefficients: return None intersection_point = get_segments_intersection_points(line, coefficients) return CollisionData(intersection_point)
def get_inter_data_line_line(first_line: "Line", second_line: "Line") -> Optional[CollisionData]: coefficients = get_penetr_line_line_coeff(first_line, second_line) if not coefficients: return None intersection_point = get_segments_intersection_points(first_line, coefficients) return CollisionData(intersection_point)
def get_inter_data_segment_ray(segment: "Segment", ray: "Ray") -> Optional[CollisionData]: coefficients = get_penetr_segment_ray_coeff(segment, ray) if not coefficients: return None intersection_point = get_segments_intersection_points(segment, coefficients) length = segment.get_length() penetration_length = length - length * coefficients[0] penetration_length = min(penetration_length, length - penetration_length) return CollisionData(intersection_point, penetration_length)
def get_inter_data_line_shape_ellipse(segment: Union["Segment", "Line", "Ray"], ellipse: "Ellipse") -> \ Optional[CollisionData]: points = get_ellipse_line_intersection_points(segment, ellipse) if not points: return None elif len(points) == 2: penetration_depth = get_penttr_depth_two_points_line_ellipse( points, ellipse) else: penetration_depth = get_penttr_depth_one_point_line_ellipse( points[0], segment, ellipse.center) return CollisionData(points, penetration_depth)
def get_inter_data_line_shape_circle( segment: Union["Segment", "Line", "Ray"], circle: "Circle") -> Optional[CollisionData]: distance_to_center = segment.get_distance_to_point(circle.center) if distance_to_center > circle.radius: return None penetration_depth = circle.radius - distance_to_center points = get_circle_line_intersection_points(segment, circle) return CollisionData(points, penetration_depth)
def get_inter_data_segment_segment(first_segment: "Segment", second_segment: "Segment") -> Optional[ CollisionData]: coefficients = get_penetr_segment_segment_coeff(first_segment, second_segment) if not coefficients: return None intersection_point = get_segments_intersection_points(first_segment, coefficients) length = first_segment.get_length() penetration_length = length - length * coefficients[0] penetration_length = min(penetration_length, length - penetration_length) return CollisionData(intersection_point, penetration_length)
def get_inter_data_circle_circle( first_circle: "Circle", second_circle: "Circle") -> Optional[CollisionData]: distance_between_centres = (first_circle.center - second_circle.center).get_magnitude() radius = first_circle.radius + second_circle.radius penetration_depth = radius - distance_between_centres if penetration_depth < 0: return None elif penetration_depth == 0: points = get_one_inter_point_circle_circle(first_circle, second_circle) else: points = get_two_inter_points_circle_circle(first_circle, second_circle) return CollisionData(points, penetration_depth)
def get_inter_data_concavepolygon_concavepolygon( first_poly: "ConcavePolygon", second_poly: "ConcavePolygon") -> Optional[CollisionData]: penetration_length: float = 0.0 points = [] for side in first_poly.sides: side_inter_data = get_inter_data_segment_concavepolygon( side, second_poly) if side_inter_data: points.extend(side_inter_data.intersection_points) penetration_length = average(penetration_length, side_inter_data.penetration_depth) if len(points) == 0: return None return CollisionData(points, penetration_length)