Cross-Section: Rectangle#
The following example demonstrates how a cross-section object can be created from a combination of polygons.
This example demonstrates how to create a basic rectangular cross-section and extract its fundamental geometric properties such as area, centroid, moments of inertia, and boundaries.
Finally, the cross-section is visualized.
You can find the example as an executable Python file here.
Import Modules#
We start by importing the required classes for defining and visualizing the cross-section.
[1]:
from sstatics.core.preprocessing.geometry import Polygon
from sstatics.core.preprocessing import CrossSection
from sstatics.core.postprocessing.graphic_objects import CrossSectionGeo, ObjectRenderer
Create Geometry#
First, we define the polygon that describe the cross-section:
[2]:
rect = Polygon(
points=[(0, 0), (40, 0), (40, 40), (0, 40), (0, 0)]
)
Create Cross-Section#
We create a cross-section in rectangle shape. This cross-section can later be used to calculate mechanical properties such as area, centroid, and moments of inertia.
[3]:
cs = CrossSection(geometry=[rect])
Visualize Cross-Section#
The generated cross-section can then be visualized using the CrossSectionGraphic class.
[4]:
# Visualize the geometry-object that create the cross-section
ObjectRenderer(CrossSectionGeo(cross_section=cs), 'mpl').show()
Calculate cross-section properties#
[5]:
A = cs.area
y_s = cs.center_of_mass_y
z_s = cs.center_of_mass_z
Iy = cs.mom_of_int
width = cs.width
height = cs.height
yb, zb = cs.boundary()
y_top, y_bottom = yb[1], yb[0]
z_top, z_bottom = zb[0], zb[1]
print("=== Rectangular Cross-Section Properties ===")
print(f"Area A : {A:.4f}")
print(f"Centroid y_s, z_s : ({y_s:.4f}, {z_s:.4f})")
print(f"Moment of inertia Iy : {Iy:.3f}")
print(f"Width, Height : {width:.4f}, {height:.4f}")
print(f"Boundary in y-direction : top = {y_top:.4f}, "
f"bottom = {y_bottom:.4f}")
print(f"Boundary in z-direction : top = {z_top:.4f}, "
f"bottom = {z_bottom:.4f}")
=== Rectangular Cross-Section Properties ===
Area A : 1600.0000
Centroid y_s, z_s : (20.0000, 20.0000)
Moment of inertia Iy : 213333.333
Width, Height : 40.0000, 40.0000
Boundary in y-direction : top = 40.0000, bottom = 0.0000
Boundary in z-direction : top = 0.0000, bottom = 40.0000