| Crates.io | trussx |
| lib.rs | trussx |
| version | 0.2.0 |
| created_at | 2021-02-03 21:29:00.548521+00 |
| updated_at | 2025-10-17 23:30:38.234869+00 |
| description | Utilities for designing and analyzing truss structures |
| homepage | https://github.com/cmccomb/trussx |
| repository | https://github.com/cmccomb/trussx |
| max_upload_size | |
| id | 350234 |
| size | 59,417 |
Utilities for building and analysing pin-jointed truss structures. The crate provides a small, strongly-typed API for creating joints and members, applying loads and supports, and running a linear elastic analysis in three dimensions.
Add the dependency to your Cargo.toml:
[dependencies]
trussx = "0.2"
use trussx::{force, point, Truss};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a new truss structure
let mut truss = Truss::new();
// Define joints
let a = truss.add_joint(point(0.0, 0.0, 0.0));
let b = truss.add_joint(point(1.0, 0.0, 0.0));
// Apply supports and loads
truss.set_support(a, [true, true, true])?;
truss.set_support(b, [false, true, true])?;
truss.set_load(b, force(-1000.0, 0.0, 0.0))?;
// Define member between joints
let ab = truss.add_member(a, b);
// Member properties must be strictly positive to represent a physical bar.
truss.set_member_properties(ab, 0.01, 200.0e9)?;
// Run the analysis and unwrap the result
truss.evaluate()?;
// Retrieve and print the displacement at joint B
let displacement = truss.joint_displacement(b).unwrap();
println!("ux = {:.3e} m", displacement.x);
Ok(())
}
Both the cross-sectional area and elastic modulus must be strictly positive. The library
rejects zero or negative inputs with a descriptive
TrussEditError so incorrect
data is surfaced before attempting an analysis.
The project includes unit tests that validate the analysis results for a simple bar in tension and ensure meaningful error reporting when required data is missing. Run the full suite with:
cargo test
Assign a yield strength to each member with set_member_yield_strength to enable factor of
safety calculations. During Truss::evaluate the library compares the absolute yield
strength to the absolute axial stress for each analysed member and stores the ratio. You can
read the value back with member_factor_of_safety.
member_factor_of_safety returns None when:
The repository includes an executable example that demonstrates the workflow end-to-end:
cargo run --example factor_of_safety
See examples/factor_of_safety.rs for the full
source. The integration tests under tests/ mirror the same
cantilever scenario to provide executable documentation for the API without
requiring a standalone CLI.