How can I use graph object info to find: areas, number of sides, and perimeter lengths of a each connected polygon within a network of polygons?

3 visualizaciones (últimos 30 días)
I was told by an MVP in the MathWorks community, "You can save the graph object, G, which contains all the connection information. You should read up on the capabilities of graph objects, as they allow you to do many things!
https://www.mathworks.com/help/matlab/ref/graph.html#d117e525223". However, I was never told how to do this and the link does not provide information on how to do this either. Can someone explain how I could use the attached graph object info to find: areas, number of sides, and perimeter lengths of a each connected polygon within a network of polygons?
Thanks in advance for your help!

Respuesta aceptada

Matt J
Matt J el 9 de Dic. de 2019
Editada: Matt J el 9 de Dic. de 2019
Using one of my recent FEX postings,
you should be able to convert a TripletGraph object tg to a polyshape array.
function [pshape,pgonNodes] = getPolyshapes(tg)
%
%IN:
%
% tg: TripletGraph object
%
%OUT:
%
% pshape: polyshape array. Each pshape(i) is a constituent polygon.
% pgonNodes: A cell array such that pgonNodes{i} contain the node indices of the
% i-th polygon.
G=tg.CGraph;
x=tg.C(:,1);
y=tg.C(:,2);
[pshape,pgonNodes]=polyshape( spatialgraph2D(G,x,y) );
end
  24 comentarios
Steve
Steve el 12 de Dic. de 2019
Editada: Steve el 13 de Dic. de 2019
Well, we know the chord-lengths (c) and arc-lengths (s) of each edge. We also know the radii (r), and thus the central angles for the same. So, we can definitely calculate the segment areas via the following equation: circular segment area = (1/2)*(r^2)*((180/Pi)*alpha - sin(alpha)). I am just not sure how to have Matlab to do it (in terms of syntax, etc.). Also, I'm not sure how to set up isinterior() to determine concavity (for +/- areas). Have any suggestions on how to set this up? Thanks again.

Iniciar sesión para comentar.

Más respuestas (1)

Catalytic
Catalytic el 9 de Dic. de 2019
Editada: Matt J el 9 de Dic. de 2019
Your attachment doesn't contain a graph object. However, perhaps it will help to mention that if you have the vertices of a polygon, you can use it to create a polyshape object.
With the polygon represented in polyshape form,
>> p=polyshape([0,0; 0 1;1 2; 1 0])
p =
polyshape with properties:
Vertices: [4×2 double]
NumRegions: 1
NumHoles: 0
you can query all the kinds of things that you mentioned. For instance,
>> area(p)
ans =
1.5000
>> perimeter(p)
ans =
5.4142
>> numsides(p)
ans =
4
>> plot(p)
untitled.png
  2 comentarios
Steve
Steve el 9 de Dic. de 2019
Thanks for your response Matt, but I don't know how to input the vertices from your previous code's output files into the polyshape code. Can you explain how to do this?

Iniciar sesión para comentar.

Categorías

Más información sobre Sparse Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by