How do I plot the cross sectional area and centroid of an I-Beam using pgon ?
3 次查看(过去 30 天)
显示 更早的评论
How do I plot the cross sectional area and centroid of an I-Beam using pgon ? My code, below did not work.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1651386/image.jpeg)
% 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 个评论
采纳的回答
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)
[Cx Cy] = centroid(Ibeam)
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 Exchange 中查找有关 Particle & Nuclear Physics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!