scale = 100 nb = int(sys.argv[1]) points = [(scale * random.random(), scale * random.random()) for i in range(nb)] else: points = [ (0, 40), (100, 60), (40, 0), (50, 100), (90, 10), # (50,50), ] fig = plot.figure() triangles = triangulation.delaunay_bowyer_watson(points) delaunay_edges = triangulation.edges_of(triangles) voronoi_graph = dual(triangles) voronoi_edges = graph.edges_of(voronoi_graph) print voronoi_edges ax = fig.add_subplot(111) ax.set_aspect('equal') uberplot.scatter_segments(ax, delaunay_edges, facecolor="blue") uberplot.plot_segments(ax, delaunay_edges, edgecolor="blue") uberplot.scatter_segments(ax, voronoi_edges, facecolor="red") uberplot.plot_segments(ax, voronoi_edges, edgecolor="red") plot.show()
line_inter = [] for s0 in segments: for s1 in segments: if s0 != s1: s = segment_intersection( s0, s1 ) if s is not None: seg_inter.append(s) l = line_intersection( s0, s1 ) if l is not None: line_inter.append(l) fig = plot.figure() ax = fig.add_subplot(121) uberplot.plot_segments( ax, segments, linewidth=0.5, edgecolor = "blue" ) uberplot.scatter_points( ax, points, edgecolor="blue", facecolor="blue", s=120, alpha=1, linewidth=1 ) uberplot.scatter_points( ax, line_inter, edgecolor="none", facecolor="green", s=60, alpha=0.5 ) uberplot.scatter_points( ax, seg_inter, edgecolor="none", facecolor="red", s=60, alpha=0.5 ) ax.set_aspect('equal') # collinear test demo if len(sys.argv) > 1: scale = 100 nb = int(sys.argv[1]) triangles = [] for t in range(nb): triangles.append( [ [scale*random.random(),scale*random.random()] for i in range(3)] ) # forced collinear t = [ [scale*random.random(),scale*random.random()] for i in range(2)]
maxph = 0 for i in phero: maxph = max(maxph, max(phero[i].values())) # ant colony # pheromones for i in phero: for j in phero[i]: if i == j: continue nph = phero[i][j] / maxph seg = [(i, j)] # LOGN( nph,seg ) uberplot.plot_segments(ax, seg, alpha=0.01 * nph, linewidth=1 * nph, **theme["pheromones"]) # uberplot.scatter_segments( ax, seg, color="red", alpha=0.5, linewidth=nph ) if not ask_for.noplot_tour: for traj in trajs: LOGN("\ttraj", len(traj), "points") # best tour uberplot.plot_segments(ax, utils.tour(traj), **theme["tour"]) if not ask_for.noplot_penrose: LOGN("\ttiling", len(penrose_segments), "segments") uberplot.plot_segments(ax, penrose_segments, **theme["penrose"]) if not ask_for.noplot_triangulation:
import utils import uberplot import matplotlib.pyplot as plot if len(sys.argv) > 1: scale = 100 nb = int(sys.argv[1]) points = [ (scale*random.random(),scale*random.random()) for i in range(nb)] else: points = [ (0,40), (100,60), (40,0), (50,100), (90,10), # (50,50), ] fig = plot.figure() triangles = delaunay_bowyer_watson( points, do_plot = fig ) edges = edges_of( triangles ) ax = fig.add_subplot(111) ax.set_aspect('equal') uberplot.scatter_segments( ax, edges, facecolor = "red" ) uberplot.plot_segments( ax, edges, edgecolor = "blue" ) plot.show()
seg_inter = [] line_inter = [] for s0 in segments: for s1 in segments: if s0 != s1: s = segment_intersection(s0, s1) if s is not None: seg_inter.append(s) l = line_intersection(s0, s1) if l is not None: line_inter.append(l) fig = plot.figure() ax = fig.add_subplot(121) uberplot.plot_segments(ax, segments, linewidth=0.5, edgecolor="blue") uberplot.scatter_points(ax, points, edgecolor="blue", facecolor="blue", s=120, alpha=1, linewidth=1) uberplot.scatter_points(ax, line_inter, edgecolor="none", facecolor="green", s=60, alpha=0.5) uberplot.scatter_points(ax, seg_inter,
scale = 100 nb = int(sys.argv[1]) points = [ (scale*random.random(),scale*random.random()) for i in range(nb)] else: points = [ (0,40), (100,60), (40,0), (50,100), (90,10), # (50,50), ] fig = plot.figure() triangles = triangulation.delaunay_bowyer_watson( points ) delaunay_edges = triangulation.edges_of( triangles ) voronoi_graph = dual( triangles ) voronoi_edges = graph.edges_of( voronoi_graph ) print voronoi_edges ax = fig.add_subplot(111) ax.set_aspect('equal') uberplot.scatter_segments( ax, delaunay_edges, facecolor = "blue" ) uberplot.plot_segments( ax, delaunay_edges, edgecolor = "blue" ) uberplot.scatter_segments( ax, voronoi_edges, facecolor = "red" ) uberplot.plot_segments( ax, voronoi_edges, edgecolor = "red" ) plot.show()
# print(quad) # sys.stderr.write( "%i points in the quadtree / %i points\n" % (len(quad), len(points)) ) fig = plot.figure() ax = fig.add_subplot(111) ax.set_aspect('equal') # Plot the whole quad tree and its points. # Iterating over the quadtree will generate points, thus list(quad) is equivalent to quad.points() uberplot.scatter_points( ax, list(quad), facecolor="green", edgecolor="None") for q in quad.quadrants: edges = list( utils.tour(as_rect(q)) ) uberplot.plot_segments( ax, edges, edgecolor = "blue", alpha = 0.1, linewidth = 2 ) # Plot a random query on the quad tree. # Remember a quadrant is ( (orig_y,orig_y), width ) minp = ( round(random.uniform(-n,n),2), round(random.uniform(-n,n),2) ) rand_quad = ( minp, round(random.uniform(0,n),2) ) # Asking for a quadrant will query the quad tree and return the corresponding points. uberplot.scatter_points( ax, quad[rand_quad], facecolor="None", edgecolor="red", alpha=0.5, linewidth = 2 ) edges = list( utils.tour(as_rect(rand_quad)) ) uberplot.plot_segments( ax, edges, edgecolor = "red", alpha = 0.5, linewidth = 2 ) plot.show() assert(len(points) == len(quad))
if not ask_for.noplot_pheromones: LOGN( "\tpheromones",len(phero),"nodes" )#,"x",len(phero[traj[0]]) ) maxph=0 for i in phero: maxph = max( maxph, max(phero[i].values())) # ant colony # pheromones for i in phero: for j in phero[i]: if i == j: continue nph = phero[i][j]/maxph seg = [(i,j)] # LOGN( nph,seg ) uberplot.plot_segments( ax, seg, alpha=0.01*nph, linewidth=1*nph, **theme["pheromones"] ) # uberplot.scatter_segments( ax, seg, color="red", alpha=0.5, linewidth=nph ) if not ask_for.noplot_tour: for traj in trajs: LOGN( "\ttraj",len(traj),"points" ) # best tour uberplot.plot_segments( ax, utils.tour(traj), **theme["tour"]) if not ask_for.noplot_penrose: LOGN( "\ttiling",len(penrose_segments),"segments" ) uberplot.plot_segments( ax, penrose_segments, **theme["penrose"]) if not ask_for.noplot_triangulation: LOGN( "\ttriangulation",len(triangulation_edges),"edges" ) uberplot.plot_segments( ax, triangulation_edges, **theme["triangulation"])
import utils import uberplot import matplotlib.pyplot as plot if len(sys.argv) > 1: scale = 100 nb = int(sys.argv[1]) points = [(scale * random.random(), scale * random.random()) for i in range(nb)] else: points = [ (0, 40), (100, 60), (40, 0), (50, 100), (90, 10), # (50,50), ] fig = plot.figure() triangles = delaunay_bowyer_watson(points, do_plot=fig) edges = edges_of(triangles) ax = fig.add_subplot(111) ax.set_aspect('equal') uberplot.scatter_segments(ax, edges, facecolor="red") uberplot.plot_segments(ax, edges, edgecolor="blue") plot.show()
ax = fig.add_subplot(111) ax.set_aspect('equal') # Plot the whole quad tree and its points. # Iterating over the quadtree will generate points, thus list(quad) is equivalent to quad.points() uberplot.scatter_points(ax, list(quad), facecolor="green", edgecolor="None") for q in quad.quadrants: edges = list(utils.tour(as_rect(q))) uberplot.plot_segments(ax, edges, edgecolor="blue", alpha=0.1, linewidth=2) # Plot a random query on the quad tree. # Remember a quadrant is ( (orig_y,orig_y), width ) minp = (round(random.uniform(-n, n), 2), round(random.uniform(-n, n), 2)) rand_quad = (minp, round(random.uniform(0, n), 2)) # Asking for a quadrant will query the quad tree and return the corresponding points. uberplot.scatter_points(ax, quad[rand_quad], facecolor="None", edgecolor="red", alpha=0.5, linewidth=2) edges = list(utils.tour(as_rect(rand_quad)))