def compute_reflection(ray: Ray, surface: Segment, intensity: float,
                       reflective_factor: float) -> (Ray, float):
    """
    Compute reflection of ray from given surface. Intensity of ray is multiplied by reflective factor of the surface.

    :param ray: Ray that should be reflected
    :param surface: Reflective surface segment
    :param intensity:
    :param reflective_factor:
    :return: Reflected ray
    """
    all_intersections = ray.intersection(surface)
    if len(all_intersections) != 1:
        return None
    intersection = all_intersections[0]
    orig_point = ray.p1
    parallel = surface.parallel_line(orig_point)
    perpendicular = surface.perpendicular_line(intersection)
    meet_point = parallel.intersection(perpendicular)[0]
    x_diff = (meet_point.x - orig_point.x)
    y_diff = (meet_point.y - orig_point.y)
    new_point = Point(meet_point.x + x_diff, meet_point.y + y_diff)
    reflected_ray = Ray(intersection, new_point)
    ray_intensity = intensity * reflective_factor
    return reflected_ray, ray_intensity
Example #2
0
def explore_next(image, point, points_map):
    """ Explore nearest zones """

    area_points = list(get_area_points(image, point, points_map))
    for points_pair in itertools.combinations(area_points, 2):
        segment = Segment(points_pair[0], points_pair[1])
        if segment.length == 0:  # is the same point
            continue
        mid = segment.midpoint
        p_line = segment.perpendicular_line(mid)
        vec = p_line.p2 - p_line.p1
        if abs(vec.x) < ZERO_EPS_EXPLORER:
            yield mid + (0, RADIUS_EXPLORER * vec.y / abs(vec.y))
            yield mid - (0, RADIUS_EXPLORER * vec.y / abs(vec.y))
        elif abs(vec.y) < ZERO_EPS_EXPLORER:
            yield mid + (RADIUS_EXPLORER * vec.x / abs(vec.x), 0)
            yield mid - (RADIUS_EXPLORER * vec.x / abs(vec.x), 0)
        else:
            yield mid + (vec.x / abs(vec.x),
                         RADIUS_EXPLORER * vec.y / abs(vec.y))
            yield mid - (vec.x / abs(vec.x),
                         RADIUS_EXPLORER * vec.y / abs(vec.y))
Example #3
0
def get_byssec_segment(x_coord, y_coord):
    segment = Segment(x_coord, y_coord)
    midpoint = segment.midpoint
    perpendicular_segment = segment.perpendicular_line(midpoint)
    return segment.perpendicular_bisector()