const PI: f64 = std::f64::consts::PI;
pub trait Beam {
fn area(&self) -> f64;
fn moment_of_inertia(&self) -> f64;
fn section_modulus(&self) -> f64;
fn radius_of_gyration(&self) -> f64 {
(self.moment_of_inertia() / self.area()).powf(0.5)
}
}
#[derive(Debug)]
pub struct PolygonalBeam {
pub circumscribed_radius: f64, pub inscribed_radius: f64, pub number_sides: i32, pub side_length: f64, }
impl PolygonalBeam {
pub fn new(side_length: f64, number_sides: i32) -> PolygonalBeam {
PolygonalBeam {
circumscribed_radius: side_length / 2.0 / (PI / f64::from(number_sides)).sin(),
inscribed_radius: side_length / 2.0 / (PI / f64::from(number_sides)).tan(),
number_sides,
side_length,
}
}
}
impl Beam for PolygonalBeam {
fn area(&self) -> f64 {
f64::from(self.number_sides) * self.side_length * self.inscribed_radius / 2.0
}
fn moment_of_inertia(&self) -> f64 {
self.area() / 24.0 * (6.0 * self.circumscribed_radius.powi(2) - self.side_length.powi(2))
}
fn section_modulus(&self) -> f64 {
self.moment_of_inertia() / self.inscribed_radius
}
}
#[derive(Debug)]
pub struct TrapezoidalBeam {
pub minor: f64,
pub major: f64,
pub height: f64,
diff_lengths: f64,
}
impl TrapezoidalBeam {
pub fn new(minor: f64, major: f64, height: f64) -> TrapezoidalBeam {
TrapezoidalBeam {
minor,
major,
height,
diff_lengths: major - minor,
}
}
}
impl Beam for TrapezoidalBeam {
fn area(&self) -> f64 {
(self.minor + self.major) / 2.0 * self.height
}
fn moment_of_inertia(&self) -> f64 {
(6.0 * self.minor.powi(2)
+ 6.0 * self.minor * self.diff_lengths
+ self.diff_lengths.powi(2))
/ (36.0 * (2.0 * self.minor + self.diff_lengths))
* self.height.powi(3)
}
fn section_modulus(&self) -> f64 {
(6.0 * self.minor.powi(2)
+ 6.0 * self.minor * self.diff_lengths
+ self.diff_lengths.powi(2))
/ (12.0 * (3.0 * self.minor + 2.0 * self.diff_lengths))
* self.height.powi(2)
}
}
#[derive(Debug)]
pub struct IBeam {
pub width: f64,
pub height: f64,
pub flange: f64, pub web: f64, pub web_height: f64,
}
impl IBeam {
pub fn new(width: f64, height: f64, flange: f64, web: f64) -> IBeam {
IBeam {
width,
height,
flange,
web,
web_height: height - 2.0 * flange,
}
}
}
impl Beam for IBeam {
fn area(&self) -> f64 {
2.0 * self.width * self.flange + self.web * self.web_height
}
fn moment_of_inertia(&self) -> f64 {
(self.width * self.height.powi(3) - self.width * self.web_height.powi(3)
+ self.web * self.web_height.powi(3))
/ 12.0
}
fn section_modulus(&self) -> f64 {
(self.width * self.height.powi(2)
- self.web_height.powi(3) / self.height * (self.width - self.web))
/ 6.0
}
}
#[derive(Debug)]
pub struct CircularBeam {
pub rad: f64,
pub dia: f64,
}
impl CircularBeam {
pub fn new(rad: f64) -> CircularBeam {
CircularBeam {
rad,
dia: 2.0 * rad,
}
}
}
impl Beam for CircularBeam {
fn area(&self) -> f64 {
PI * self.rad.powi(2)
}
fn moment_of_inertia(&self) -> f64 {
self.area() / 4.0 * self.rad.powi(2)
}
fn section_modulus(&self) -> f64 {
self.moment_of_inertia() / self.rad
}
}
#[derive(Debug)]
pub struct CircularTube {
pub inner_radius: f64,
pub outer_radius: f64,
}
impl CircularTube {
pub fn new(inner_radius: f64, outer_radius: f64) -> CircularTube {
CircularTube {
inner_radius,
outer_radius,
}
}
}
impl Beam for CircularTube {
fn area(&self) -> f64 {
PI * (self.outer_radius.powi(2) - self.inner_radius.powi(2))
}
fn moment_of_inertia(&self) -> f64 {
PI / 4.0 * (self.outer_radius.powi(4) - self.inner_radius.powi(4))
}
fn section_modulus(&self) -> f64 {
PI / 4.0 * (self.outer_radius.powi(4) - self.inner_radius.powi(4)) / self.outer_radius
}
}
pub struct Load {
pub origin: f64,
pub end: f64,
pub magnitude: Box<Fn(f64) -> f64>,
}
impl Load {
pub fn new(origin: f64, end: f64, magnitude: fn(x: f64) -> f64) -> Load {
Load {
origin,
end,
magnitude: Box::new(magnitude),
}
}
pub fn point(location: f64, magnitude: f64) -> Load {
Load {
origin: location,
end: location,
magnitude: Box::new(move |_any_x_value| magnitude),
}
}
pub fn distributed(origin: f64, end: f64, magnitude: f64) -> Load {
Load {
origin,
end,
magnitude: Box::new(move |_x| magnitude),
}
}
}
pub enum SupportType {
Fixed,
Simple,
}
pub struct Support {
pub support_type: SupportType,
pub location: f64,
}