The Beam Analysis Library is a Python module for analyzing simply supported beams under various loading conditions. It calculates support reactions, shear forces, and bending moments, and provides interactive visualizations using Plotly.
- Multiple load types: Point loads, point moments, uniformly distributed loads (UDL), and linearly varying distributed loads (LDL)
- Automatic reaction calculation for simply supported beams
- Shear force and bending moment diagrams with interactive plotting
- Flexible support locations (supports don't have to be at beam ends)
- Comprehensive results with summary reports
- Currently supports only simply supported beams (pins and rollers)
- Linear loads must be triangular (one end zero)
# Install beam_analysis.py
# Copy beam_analysis.py to your project folderpip install numpy plotlyfrom beam_analysis import BeamAnalyzer
# Create a beam (span = 15m, supports at 0m and 15m)
beam = BeamAnalyzer(span=15, left_support=0, right_support=15)
# Add a point load (40 kN downward at 12m)
beam.add_point_load(location=12, y_mag=-40)
# Add distributed loads
beam.add_distributed_load(start=0, end=5, magnitude=-5)
beam.add_distributed_load(start=5, end=10, magnitude=-20)
# Calculate and visualize
beam.calculate_shear_moment()
beam.plot_diagrams()
beam.get_summary()BeamAnalyzer(span, left_support=0, right_support=None, divs=1000)Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
span |
float | Required | Total length of the beam (m) |
left_support |
float | 0 | Distance from left end to left support (m) |
right_support |
float | None | Distance from left end to right support (m) |
divs |
int | 1000 | Number of divisions for numerical analysis |
Example:
# Beam with supports at 2m and 12m
beam = BeamAnalyzer(span=15, left_support=2, right_support=12)Adds a point load at a specific location.
| Parameter | Type | Description |
|---|---|---|
location |
float | Distance from left end (m) |
x_mag |
float | Horizontal force component (kN) |
y_mag |
float | Vertical force component (kN) |
Example:
# 50 kN downward force at 5m
beam.add_point_load(location=5, y_mag=-50)
# 30 kN horizontal force at 3m
beam.add_point_load(location=3, x_mag=30)
# 20 kN at 45° (14.14 kN horizontal, 14.14 kN vertical)
import math
angle = 45 * math.pi / 180
beam.add_point_load(location=7, x_mag=20*math.cos(angle), y_mag=-20*math.sin(angle))Adds a point moment at a specific location.
| Parameter | Type | Description |
|---|---|---|
location |
float | Distance from left end (m) |
magnitude |
float | Moment magnitude (kNm) |
Example:
# 30 kNm clockwise moment at 8m
beam.add_point_moment(location=8, magnitude=30)Adds a uniformly distributed load (UDL) over a specified range.
| Parameter | Type | Description |
|---|---|---|
start |
float | Start position (m) |
end |
float | End position (m) |
magnitude |
float | Load intensity (kN/m) |
Example:
# 10 kN/m UDL from 2m to 8m
beam.add_distributed_load(start=2, end=8, magnitude=-10)Adds a linearly varying distributed load.
| Parameter | Type | Description |
|---|---|---|
start |
float | Start position (m) |
end |
float | End position (m) |
start_mag |
float | Intensity at start (kN/m) |
end_mag |
float | Intensity at end (kN/m) |
Note: Currently supports triangular loads (one end must be zero).
Example:
# Triangular load from 5m to 10m (0 at 5m, -20 at 10m)
beam.add_linear_load(start=5, end=10, start_mag=0, end_mag=-20)Calculates support reactions (Va, Ha, Vb).
Returns: numpy.ndarray - [Va, Ha, Vb]
Example:
reactions = beam.calculate_reactions()
print(f"Va: {reactions[0]:.2f} kN")
print(f"Ha: {reactions[1]:.2f} kN")
print(f"Vb: {reactions[2]:.2f} kN")Calculates shear force and bending moment diagrams.
Returns: tuple - (shearForce, bendingMoment)
Example:
shear, moment = beam.calculate_shear_moment()
print(f"Max shear: {max(abs(shear)):.2f} kN")
print(f"Max moment: {max(abs(moment)):.2f} kNm")Generates interactive shear force and bending moment diagrams.
| Parameter | Type | Default | Description |
|---|---|---|---|
show |
bool | True | Display the plot immediately |
Returns: plotly.graph_objs.Figure
Example:
fig = beam.plot_diagrams(show=True)
# Or save to file
fig.write_html("beam_analysis.html")Prints a comprehensive summary of analysis results.
Example Output:
==================================================
BEAM ANALYSIS SUMMARY
==================================================
Span: 15.0 m
Left Support (A): 0.0 m
Right Support (B): 15.0 m
REACTIONS:
Vertical reaction at A (Va): 56.67 kN
Horizontal reaction at A (Ha): 0.00 kN
Vertical reaction at B (Vb): 38.33 kN
MAXIMUM VALUES:
Maximum Shear Force: 56.67 kN
Maximum Bending Moment: 125.00 kNm
==================================================
from beam_analysis import BeamAnalyzer
# Beam with a single point load
beam = BeamAnalyzer(span=10)
beam.add_point_load(location=5, y_mag=-100)
# Get results
beam.calculate_shear_moment()
beam.get_summary()
beam.plot_diagrams()from beam_analysis import BeamAnalyzer
beam = BeamAnalyzer(span=20)
# Multiple load types
beam.add_point_load(location=5, y_mag=-50)
beam.add_point_load(location=15, y_mag=-30)
beam.add_distributed_load(start=7, end=13, magnitude=-10)
beam.add_point_moment(location=10, magnitude=40)
beam.calculate_shear_moment()
beam.get_summary()
beam.plot_diagrams()from beam_analysis import BeamAnalyzer
# Beam overhanging on both ends
beam = BeamAnalyzer(span=12, left_support=2, right_support=10)
# Loads on overhangs
beam.add_point_load(location=0, y_mag=-20) # Left overhang
beam.add_point_load(location=12, y_mag=-20) # Right overhang
beam.add_distributed_load(start=2, end=10, magnitude=-5)
beam.calculate_shear_moment()
beam.plot_diagrams()from beam_analysis import BeamAnalyzer
import pandas as pd
beam = BeamAnalyzer(span=15)
beam.add_distributed_load(start=0, end=15, magnitude=-10)
beam.calculate_shear_moment()
# Get data for export
shear, moment = beam.shearForce, beam.bendingMoment
# Create DataFrame
df = pd.DataFrame({
'Distance': beam.X,
'Shear_Force': shear,
'Bending_Moment': moment
})
# Export to CSV
df.to_csv('beam_results.csv', index=False)pip install plotlyIncrease divs parameter:
beam = BeamAnalyzer(span=15, divs=5000)Ensure right_support <= span:
# This is wrong
beam = BeamAnalyzer(span=10, right_support=12)
# This is correct
beam = BeamAnalyzer(span=10, right_support=10) Currently, one end of the linear load must be zero:
# This works
beam.add_linear_load(start=0, end=5, start_mag=0, end_mag=-10)
# This works
beam.add_linear_load(start=0, end=5, start_mag=-10, end_mag=0)
# This may not work as expected
beam.add_linear_load(start=0, end=5, start_mag=-10, end_mag=-5)MIT License
Copyright (c) 2026 Rico Viviers
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
For questions or suggestions, please create an issue in the project repository.