フィルターのクリア

How do I plot the cross sectional area and centroid of an I-Beam using pgon ?

1 回表示 (過去 30 日間)
How do I plot the cross sectional area and centroid of an I-Beam using pgon ? My code, below did not work.
% assuming the x-y plane origin is (0,0)
x = [ 0 0 1 1 2 2 3 3 4 4 5 5]; % x coords
y = [ 9 10 0 1 1 9 1 9 0 1 9 10]; % y coords ];
pgon = polyshape(x,y);
A = area(pgon)
[Cx Cy] = centroid(pgon);
h = plot(pgon)
hold on
plot(Cx,Cy,'r*', 'markerSize', 10)
grid minor
h(1).FaceColor = [0 0 1];
disp('centroid at (x,y) coords:'), disp([Cx Cy])

採用された回答

John D'Errico
John D'Errico 2024 年 3 月 25 日
編集済み: John D'Errico 2024 年 3 月 25 日
The funny thing is, your code was indeed essentially correct. You just started out wrongly.
x = [ 0 0 1 1 2 2 3 3 4 4 5 5]; % x coords
y = [ 9 10 0 1 1 9 1 9 0 1 9 10]; % y coords
Do those points, in THAT SPECIFIC sequence, represent the shape in question? NO. Of course not! I'm not even sure where you got that set of points. If you have problems in this, I would recommend you start with a piece of graph paper, draw the object to scale, then take the corner coordinates from there. Remember, you need the points in a SPECIFIC sequence, since they must represent the perimeter of the beam in question. If you choose some random sequence, polyshape will not figure out what you want. Software does not read minds. Ok, not yet. And I'm not totally sure I want to see a future where it does.
If, instead, we do this:
x = [1 4 4 3 3 5 5 0 0 2 2 1]; % x coords
y = [0 0 1 1 9 9 10 10 9 9 1 1]; % y coords
See that I started at one corner of the I-beam cross section, then worked around, IN SEQUENCE. I chose a counter-clockwise sequence. Of course, in this age of digital clocks, do people even know what that means? ;-)
Ibeam = polyshape(x,y);
plot(Ibeam)
axis equal
A = area(Ibeam)
A = 16
[Cx Cy] = centroid(Ibeam)
Cx = 2.5000
Cy = 5.5625
hold on
plot(Cx,Cy,'r*', 'markerSize', 10)
That seems to work. The area seems correct too, based on simply counting squares. The centroid seems about right too.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeParticle & Nuclear Physics についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by