示例#1
0
def check_problem():
    movie = Movie()
    f = 1

    def aff(x, y):
        return P(x, y)

    stone = Polygon([
        aff(0.09897029702970297, 0.27443716679360247),
        aff(0.11047372429550648, 0.2750952018278751),
        aff(0.10981568926123382, 0.2865955826351866),
        aff(0.09831530845392232, 0.285940594059406)
    ])
    center = aff(0.08183068719268435, 0.28569424117242365)
    radius = 0.0164719687883 * f
    step = 0.000823598439415 * f

    stones = PolygonSet()
    stones.add(stone)
    allowable = stones.open_direction_for_circle(center, radius, step)

    l = [(stone, "red"), (Circle(center, radius), "green"),
         (allowable, "black")]

    movie.background(l)
    movie.just_draw()
    exit(0)
示例#2
0
def check_open_directions_for_circle_avoiding_segment2():
    radius = 0.25
    step = 0.15
    center = P(0.5, 0.5)
    circ = Circle(center, radius)
    p = P(0.12661771955, 0.59179988647)
    q = P(0.22661771955, 0.79179988647)

    seg = S(p, q)
    directions = GRegion.open_directions_for_circle_avoiding_segment(
        circ, seg, step)
    shift = seg.dir.perp().resize(radius)
    box = Polygon([p - shift, p + shift, q + shift, q - shift])
    l = [
        (Circle(center, step), "lightgreen"),
        (box, "lightgrey"),
        # (Circle(p, radius), "lightgrey"),
        # (Circle(q, radius), "lightgrey"),
        (directions, "black"),
        (seg, "red"),
        (Circle(center, 0.004), "red")
    ]
    movie = Movie()
    movie.background(l)
    movie.just_draw()
    exit(0)
示例#3
0
def check_open_directions_for_circle_avoiding_segment3():
    placements = []
    radius = 0.25
    step = 0.15
    center = P(0.5, 0.5)
    circ = Circle(center, radius)
    for i in range(1000):
        p = P.polar(0.37, i / 1000 * 2 * np.pi) + P(0.43, 0.38)
        q = p + P(0.1, 0.2)
        seg = S(p, q)
        directions = GRegion.open_directions_for_circle_avoiding_segment(
            circ, seg, step)
        if len(directions.regions) > 1:
            shift = seg.dir.perp().resize(radius)
            print(seg.p.x, seg.p.y, seg.q.x, seg.q.y)
            box = Polygon([p - shift, p + shift, q + shift, q - shift])
            l = [(Circle(center, step), "lightgreen"), (box, "lightgrey"),
                 (Circle(p, radius), "lightgrey"),
                 (Circle(q, radius), "lightgrey"), (directions, "black"),
                 (seg, "red"), (Circle(center, 0.004), "red")]
            placements.append(l)
            movie = Movie()
            movie.background(l)
            movie.just_draw()
            break
    exit(0)
示例#4
0
def draw_gap(file_name):
    cfg = configuration.Configuration(file_name=file_name)
    gap, a, b = max_backwards(cfg.path.points)
    path = cfg.path.points
    movie = Movie()
    movie.background([(cfg, "black")])
    movie.background([(circle.Circle(path[a], cfg.cheerio_radius / 2), "green")])
    movie.background([(circle.Circle(path[b], cfg.cheerio_radius / 2), "green")])
    movie.just_draw()
    exit(0)
示例#5
0
def run_movie(cfg: configuration.Configuration, runner: run.Runner, only_plot=False,
              only_save=False):
    """Create the video."""
    movie = Movie()
    movie.background([(cfg, "black")])  # draws the cubes
    cheerios, result = run.Run(runner).run()  # runs the algorithm/analysis specified by runner
    # returns a list of points (class p) specifying the location of the load over time and a
    # boolean variable describing whether the run was successful
    print(result)
    if only_plot or only_save:
        movie.background([(MotionPath(cheerios), "green")])  # draws the simulated load path
        if only_save:
            movie.save_figure(cfg.file_name + "_image")
        else:
            movie.just_draw()  # plotting without saving
    else:
        # Creating a video of the simulated load moving through the cube maze
        to_draw = []
        # create list of tuples(Circle,str), one for each frame to be drawn in the animation
        for cheerio in cheerios:
            to_draw.append([(circle.Circle(cheerio, cfg.cheerio_radius), "green")])
        movie.run_animation(to_draw, 0)  # drawing the load
示例#6
0
def boxes(cfg, box_size_in_cheerio_radii=6, draw=True):
    if draw:
        movie = Movie()
        movie.background([(cfg, "black")])
    size = box_size_in_cheerio_radii * cfg.cheerio_radius

    index = 0
    path = cfg.path.points
    result = []
    while index < len(path) and path[index].x < 1 - size:
        p = path[index]
        box = rectangle.Rectangle(p.x, p.y - size / 2, p.x + size, p.y + size / 2)

        good = 0
        times = 10
        for i in range(times):
            cfg.start = p
            cfg.reset_runseed()
            r, sim_res = run.Run(run.SimulationRunner(cfg), containing_box=box).run()
            if sim_res:
                good += 1
            if draw:
                if sim_res:
                    color = "green"
                else:
                    color = "black"
                movie.background([(MotionPath(r), color)])

        r, ant_res = run.Run(run.AntRunner(cfg, index), containing_box=box).run()
        if draw:
            if ant_res:
                color = "green"
            else:
                color = "black"
            movie.background([(MotionPath(r), "blue")])
            box.add_text('{:.0f}%,{:.0f}%'.format(box_density(cfg, box) * 100, good / times * 100))
            movie.background([(box, color)])

        result.append((box_density(cfg, box), ant_res, good / times))
        while index < len(path) and path[index].x < box.qx:
            index += 1

    if draw:
        movie.save_figure(cfg.file_name + "_boxes")
        movie.close()
        # movie.just_draw()
    return result
示例#7
0
def remote_sensing1(cfg: configuration.Configuration, draw=False):
    if draw:
        movie = Movie()
        movie.background([(cfg, "black")])
    else:
        movie = None
    path = cfg.path.points
    index = 0
    last = 0
    count = 0
    count_good = 0
    while index < len(path):
        if path[index].x - path[last].x > cfg.cheerio_radius * 6:
            res = where_did_it_go(cfg, movie, index)
            if isinstance(res, bool):
                count += 1
                if res:
                    count_good += 1
            last = index
        index += 1
    if draw:
        movie.just_draw()
    print(cfg.file_name, count, count_good)
    return count, count_good
示例#8
0
def read_heat_map(file_name, display=True):
    stones, cheerio, nest, path = init_stones(file_name)
    movie = Movie()
    movie.background([(s, "green") for s in stones])
    h = HeatMap()
    if not file_name:
        file_name = "tmp"
    h.read_map("data/" + file_name + "_heatmap.txt")
    movie.background(h.to_draw())
    movie.background([(path, "red")])
    movie.save_figure("data/" + file_name + "_heatmap")
    if display:
        movie.just_draw()
    else:
        movie.close()
示例#9
0
def draw_distribution(sigma):
    direction = P(0.3, 0)
    stones = PolygonSet()
    stones.add(Polygon.square(P(0.6, 0.6), 0.2, 0.1))
    stones.add(Polygon.square(P(0.3, 0.6), 0.2, 0.1))
    stones.add(Polygon.square(P(0.7, 0.4), 0.2, 0.1))
    cheerio = P(0.5, 0.5)
    g = stones.open_direction_for_circle(cheerio, 0, 1)

    movie = Movie()
    movie.background([(s, "red") for s in stones])
    movie.background([(S(cheerio, direction + cheerio), "blue")])
    movie.background([(g, "black")])

    points = []
    for i in range(300):
        rand_dir = g.rand_point_normal(direction, sigma)
        # rand_dir = direction.rotate(np.random.normal(scale=sigma) * np.pi)
        points.append(cheerio + rand_dir)
    movie.background([(Circle(p, 0.0015), "blue") for p in points])

    movie.just_draw()
    exit()
示例#10
0
def just_draw_cfg(cfg: configuration.Configuration):
    print(cfg)
    movie = Movie()
    movie.background([(cfg, "black")])
    movie.just_draw()
    exit(0)