Example #1
0
 def get_vis_step(r):
     first = True
     step = []
     for p in hull:
         if not first:
             step.append(Line.from_points(step[-1], p, 'g'))
         cpy = copy(p)
         step.append(cpy)
         first = False
     if len(step) > 0:
         step.append(Line.from_points(step[-1], r, 'y'))
     cpy = copy(r)
     step.append(cpy)
     return step
Example #2
0
    def handle_click(self, event):
        button = event.button

        if not event.xdata or not event.ydata:
            return

        if button == 1:
            new_point = Point(event.xdata, event.ydata, 'black')
            prev_point = self.prev_point
            if prev_point:
                line = Line.from_points(prev_point, new_point, 'black')
                self.add_figure(line)
            else:
                self.points = []
                self.polygon = None
                self.clear_figures(False)
            self.add_figure(new_point)
            self.prev_point = new_point
            self.points.append(new_point)
            self.update_figures()
            self.wait(0.05)
        elif button == 3 and len(self.points) >= 3:
            self.clear_figures(False)
            self.polygon = Polygon(self.points, 'black')
            self.add_figure(self.polygon)
            self.update_figures(polygon=True)
            self.prev_point = None
            self.wait(0.05)
Example #3
0
 def handle_click(self, event):
     button = event.button
     if button == 1:
         new_point = Point(event.xdata, event.ydata, 'r')
         prev_point = self.prev_point
         self.add_figure(new_point)
         if prev_point:
             if prev_point.x > new_point.x:
                 (prev_point, new_point) = (new_point, prev_point)
             line = Line.from_points(prev_point, new_point, 'r')
             self.add_figure(line)
             self.segments.append(line)
             self.prev_point = None
         else:
             self.prev_point = new_point
         self.update_figures()
         self.wait(0.05)
Example #4
0
    if method == 'j':

        print 'Set:', set, 'Method: Jarvis'

        time_start = time.time()
        hull, steps = jarvis_convex_hull(points_copy, False)
        time_end = time.time()

        print (time_end - time_start), 's'

        hull, steps = jarvis_convex_hull(points_copy, True)

    for step in steps:
        plot.step()
        plot.add_all(step)
    plot.step()
    for _ in range(10):
        prev_point = hull[-1]
        for point in hull:
            plot.add(Line.from_points(prev_point, point, 'g'))
            prev_point = point
        plot.add_all(hull)
        plot.step()
    anim = plot.draw()

    if show:
        plot.show()
    else:
        anim.save('visualization_' + set + '_' + method + '.mp4', extra_args=['-vcodec', 'libx264'])
        # anim.save('visualization.gif', writer='imagemagick')