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?

2 次查看(过去 30 天)
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!

采纳的回答

Matt J
Matt J 2019-12-9
编辑:Matt J 2019-12-9
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 个评论
Steve
Steve 2019-12-12
编辑:Steve 2019-12-13
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.

请先登录,再进行评论。

更多回答(1 个)

Catalytic
Catalytic 2019-12-9
编辑:Matt J 2019-12-9
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

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by