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 ビュー (過去 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 件のコメント
Matt J
Matt J 2019 年 12 月 12 日
Like I said here, I don't think it's too bad.
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
  2 件のコメント
Steve
Steve 2019 年 12 月 9 日
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?
Steve
Steve 2019 年 12 月 9 日
Thanks also to Catalytic.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by