Code covered by the BSD License  

Highlights from
Matgraph

from Matgraph by Ed Scheinerman
Toolbox for working with simple, undirected graphs

Description of random_planar
Home > matgraph > @graph > random_planar.m

random_planar

PURPOSE ^

random_planar(g,n) --- create a random planar triangulation

SYNOPSIS ^

function random_planar(g,n)

DESCRIPTION ^

 random_planar(g,n) --- create a random planar triangulation
 This does NOT create a random "uniform" triangulation. Rather, it places
 n points at random in the plane and builds the Delaunay triangulation
 thereon.

CROSS-REFERENCE INFORMATION ^

This function calls:
  • add add --- add edge(s) to the graph
  • edges edges(g) --- list the edges in g as a 2-column matrix
  • embed embed --- create an embedding for a graph
  • resize resize(g,n) --- change the number of vertices in g to n
  • size size(g) --- returns [nv,ne] for the graph
This function is called by:

SOURCE CODE ^

0001 function random_planar(g,n)
0002 % random_planar(g,n) --- create a random planar triangulation
0003 % This does NOT create a random "uniform" triangulation. Rather, it places
0004 % n points at random in the plane and builds the Delaunay triangulation
0005 % thereon.
0006 
0007 xy = rand(n,2)*sqrt(n);
0008 resize(g,0)
0009 resize(g,n)
0010 embed(g,xy)
0011 
0012 triangles = delaunay(xy(:,1), xy(:,2));
0013 nt = size(triangles,1);
0014 
0015 edges = [triangles(:,1:2); triangles(:,2:3); triangles(:,[1,3])];
0016 edges = sortrows(edges);
0017 edges = unique(edges,'rows');
0018 add(g,edges)

Generated on Thu 13-Mar-2008 14:23:52 by m2html © 2003

Contact us at files@mathworks.com