From 61159f3cf17f092f922fb19061d160988fdc50f2 Mon Sep 17 00:00:00 2001 From: Johann Dreo Date: Mon, 12 May 2014 11:39:09 +0200 Subject: [PATCH] Plot Voronoi centers --- run_all.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/run_all.py b/run_all.py index 38df5e4..da364f7 100755 --- a/run_all.py +++ b/run_all.py @@ -15,6 +15,7 @@ import uberplot import shortpath import lindenmayer import triangulation +import voronoi parser = argparse.ArgumentParser() @@ -32,6 +33,8 @@ parser.add_argument('-m', "--pheromones", help="Load a pheromones matrix from a parser.add_argument('-g', "--triangulation", help="Do not compute the Delaunay triangulation but load it from a file", default=None, action='store', type=str, metavar="SEGMENTS") +parser.add_argument('-v', "--voronoi", help="Do not compute the Voronoï diagram but load it from a file", + default=None, action='store', type=str, metavar="POINTS") args = parser.parse_args() @@ -181,6 +184,22 @@ else: fd.write("%f %f %f %f\n" % (p0[0],p0[1],p1[0],p1[1]) ) +######################################################################## +# VORONOÏ +######################################################################## + +if args.voronoi: + voronoi_centers = utils.load_points(args.voronoi) + +else: + LOGN( "Compute the nodes of the Voronoï diagram" ) + voronoi_centers = voronoi.centers(triangulated) + + with open("d%i_voronoi_centers.points" % depth, "w") as fd: + for p in voronoi_centers: + fd.write( "%f %f\n" % (p[0],p[1]) ) + + ######################################################################## # PLOT ######################################################################## @@ -219,6 +238,9 @@ uberplot.scatter_segments( ax, penrose_segments, edgecolor=tcol, alpha=0.9, line # triangulation uberplot.plot_segments( ax, triangulation_edges, edgecolor="green", alpha=0.2, linewidth=1 ) +# Voronoï centers +uberplot.scatter_points( ax, voronoi_centers, edgecolor="none", facecolor="green", linewidth=0 ) + ax.set_aspect('equal') plot.show()