1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#![warn(clippy::all)]
#![warn(missing_docs)]
#![warn(missing_doc_code_examples)]
#![warn(clippy::missing_docs_in_private_items)]
#[derive(Clone, Copy)]
#[non_exhaustive]
pub enum StructuralShape {
Pipe {
outer_radius: f64,
thickness: f64,
},
IBeam {
width: f64,
height: f64,
web_thickness: f64,
flange_thickness: f64,
},
BoxBeam {
width: f64,
height: f64,
thickness: f64,
},
Rod {
radius: f64,
},
Rectangle {
width: f64,
height: f64,
},
}
impl StructuralShape {
pub fn moment_of_inertia_x(&self) -> f64 {
match self {
StructuralShape::Pipe {
outer_radius,
thickness,
} => {
std::f64::consts::PI * (outer_radius.powi(4) - (outer_radius - thickness).powi(4))
/ 4.0
}
StructuralShape::IBeam {
width,
height,
flange_thickness,
web_thickness,
} => {
width * height.powi(3) / 12.0
- 2.0
* ((width - web_thickness) / 2.0)
* (height - 2.0 * flange_thickness).powi(3)
/ 12.0
}
StructuralShape::BoxBeam {
width,
height,
thickness,
} => {
width * height.powi(3) / 12.0
- (width - thickness) * (height - thickness).powi(3) / 12.0
}
StructuralShape::Rod { radius } => std::f64::consts::PI * radius.powi(4) / 4.0,
StructuralShape::Rectangle { width, height } => width * height.powi(3) / 12.0,
}
}
pub fn moment_of_inertia_y(&self) -> f64 {
match self {
StructuralShape::Pipe { .. } => self.moment_of_inertia_x(),
StructuralShape::IBeam { .. } => 0.0,
StructuralShape::BoxBeam {
width,
height,
thickness,
} => {
height * width.powi(3) / 12.0
- (height - thickness) * (width - thickness).powi(3) / 12.0
}
StructuralShape::Rod { .. } => self.moment_of_inertia_x(),
StructuralShape::Rectangle { .. } => self.moment_of_inertia_x(),
}
}
pub fn area(&self) -> f64 {
match *self {
StructuralShape::Pipe {
outer_radius,
thickness,
} => std::f64::consts::PI * (outer_radius.powi(2) - (outer_radius - thickness).powi(2)),
StructuralShape::IBeam {
width,
height,
web_thickness,
flange_thickness,
} => width * height - (height - 2.0 * flange_thickness) * (width - web_thickness),
StructuralShape::BoxBeam {
width,
height,
thickness,
} => width * height - (width - thickness) * (height - thickness),
StructuralShape::Rod { radius } => std::f64::consts::PI * radius.powi(2),
StructuralShape::Rectangle { width, height } => width * height,
}
}
}