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

3 visualizaciones (últimos 30 días)
Doug Leaffer el 25 de Mzo. de 2024
Comentada: Doug Leaffer el 25 de Mzo. de 2024
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])
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

John D'Errico el 25 de Mzo. de 2024
Editada: John D'Errico el 25 de Mzo. de 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.
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.
##### 1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
Doug Leaffer el 25 de Mzo. de 2024
Thanks John. Your corrected code works fine.

Iniciar sesión para comentar.

### Categorías

Más información sobre Particle & Nuclear Physics en Help Center y File Exchange.

R2022a

### Community Treasure Hunt

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

Start Hunting!

Translated by