Geometry Manipulation#
This example will showcase the built-in geometry manipulation tools in sectionproperties
:
Align
Mirror
Rotate
Shift
Split
Offset
Import Modules#
We start by importing the rectangular_section(), channel_section() and rectangular_hollow_section() functions
[1]:
from sectionproperties.pre.library import (
rectangular_section,
channel_section,
rectangular_hollow_section,
)
Align#
This example will align various rectangles to each other by using the align_to() and align_center() methods.
[2]:
# create a central rectangle
rect_centre = rectangular_section(d=150, b=100)
# align a square to the central rectangle's right side
sq_right = rectangular_section(d=20, b=20).align_to(other=rect_centre, on="left")
# combine two geometries and plot
geom = rect_centre + sq_right
geom.plot_geometry()
[2]:
<Axes: title={'center': 'Cross-Section Geometry'}>
[3]:
# align a square to the middle of the central rectangle's top side
sq_center = (
rectangular_section(d=20, b=20)
.align_center(align_to=rect_centre)
.align_to(other=rect_centre, on="top")
)
# combine with the previous geometry and plot
geom += sq_center
geom.plot_geometry()
[3]:
<Axes: title={'center': 'Cross-Section Geometry'}>
[4]:
# align a square to the centre of the central rectangle's right inner side
sq_right = (
rectangular_section(d=20, b=20)
.align_center(align_to=rect_centre)
.align_to(other=rect_centre, on="right", inner=True)
)
# combine with the previous geometry and plot
geom = geom - sq_right + sq_right # note we first subtract to avoid overlapping regions
geom.plot_geometry()
[4]:
<Axes: title={'center': 'Cross-Section Geometry'}>
Mirror#
The following example demonstrates how geometry objects can be mirrored. Two 200PFCs are placed back-to-back by using the mirror_section() method.
[5]:
# create RHS PFC
pfc_right = channel_section(d=200, b=75, t_f=12, t_w=6, r=12, n_r=8)
# create LHS PFC by mirroring the RHS PFC
pfc_left = pfc_right.mirror_section(axis="y", mirror_point=(0, 0))
# combine the two PFCs into one geometry and plot the geometry
geom = pfc_right + pfc_left
geom.plot_geometry()
[5]:
<Axes: title={'center': 'Cross-Section Geometry'}>
Rotate#
The following example rotates the above generated geometry counter-clockwise by 10 degrees by using the rotate_section() method.
[6]:
geom = geom.rotate_section(angle=10)
geom.plot_geometry()
[6]:
<Axes: title={'center': 'Cross-Section Geometry'}>
Shift#
In this example we use the calculate_extents() method to get the coordinates of the bounding box of the above geometry. We use these coordinates to shift the geometry such that all x
and y
values are positive by shifting the bottom left corner of the bounding box to the origin. The
shift_section() method is used to accomplish this.x
[7]:
x_min, _, y_min, _ = geom.calculate_extents()
geom_t = geom.shift_section(x_offset=-x_min, y_offset=-y_min)
geom_t.plot_geometry()
[7]:
<Axes: title={'center': 'Cross-Section Geometry'}>
Split#
In this example, we use the split_section() method to split the above geometry by a vertical line at x = 102
.
[8]:
right_geoms, left_geoms = geom.split_section(point_i=(102, 0), vector=(0, 1))
# combine resultant geometries into a CompoundGeometry object
from sectionproperties.pre import CompoundGeometry
geom = CompoundGeometry(geoms=left_geoms + right_geoms)
geom.plot_geometry()
[8]:
<Axes: title={'center': 'Cross-Section Geometry'}>
Note how control points are added automatically as required.
Offset#
In this example we show how we can erode and dilate the perimeters of geometry objects by using the offset_perimeter() method.
We start with a 100 x 50 x 6 RHS and create the following sections:
2.0 mm external erosion
1.0 mm external dilation
1.5 mm external and internal erosion
[9]:
rhs_base = rectangular_hollow_section(d=100, b=50, t=6, r_out=15, n_r=8)
rhs_base.plot_geometry(title="RHS Base")
rhs_base.offset_perimeter(amount=-2.0).plot_geometry(title="RHS 1")
rhs_base.offset_perimeter(amount=1.0).plot_geometry(title="RHS 2")
rhs_base.offset_perimeter(amount=-1.5, where="all").plot_geometry(title="RHS 3")
[9]:
<Axes: title={'center': 'RHS 3'}>