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

7 Ansichten (letzte 30 Tage)
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])

Akzeptierte Antwort

John D'Errico
John D'Errico am 25 Mär. 2024
Bearbeitet: John D'Errico am 25 Mär. 2024
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.

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Performance finden Sie in Help Center und File Exchange

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by