image thumbnail

spatialgraph2D

version 2.0.3 (3.3 KB) by Matt J
Creates a graph object with 2D spatial locations associated with the nodes

142 Downloads

Updated 15 Aug 2020

View License

This submission defines a graph class which allows 2D (x,y) location data to be attached to the nodes. It was designed with mosaic graphs in mind. By a mosaic graph, I mean a graph in which distinct edges may intersect one another only at the nodes. Currently, its main capability is decomposing a mosaic graph into its constituent polygons. As an example, given the graph,

s = [1 1 1 2 3 3 4 4 5 6 7 6 8 9 10 10 12 12 13 14 15 16 17 17 18 19 20 21 20 25];
t = [2 8 18 3 4 23 5 21 6 7 8 11 9 10 11 12 14 13 15 18 16 17 18 25 19 20 1 22 24 26];
G = graph(s,t);

we associate the nodes of G to the following x, y data

x = [0.5 0 0 0 0.5 1 1.5 2 3 3 3 5.5 6 4 6 6 4 3 2 0.5 -1 -2 -1 1.5 4.5 4.5];
y = [0 0.5 1 1.5 2 2 1.5 1 1 1.5 2 1 0.5 0.5 0 -1 -1 -0.5 -1 -1 1 0.5 0.5 -0.5 -0.5 0];

We create a spatialgraph2D object as follows,

obj=spatialgraph2D(G,x,y);

Then, we can obtain a polyshape array of all the constituent polygons as follows,

pgon=polyshape(obj);

To visualize, use the following pair of overlaid plots. This was used to generate the image thumbnail above.

plot(obj);
hold on
plot(pgon);
hold off

Cite As

Matt J (2021). spatialgraph2D (https://www.mathworks.com/matlabcentral/fileexchange/73630-spatialgraph2d), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2018a
Compatible with R2016b and later releases
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!