-
-
Notifications
You must be signed in to change notification settings - Fork 266
Expand file tree
/
Copy pathinertia.py
More file actions
217 lines (167 loc) · 6.7 KB
/
Copy pathinertia.py
File metadata and controls
217 lines (167 loc) · 6.7 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
"""Utilities related to inertia tensor transformations.
This module centralizes dynamic helpers for applying the parallel axis
theorem (PAT). It lives inside ``rocketpy.mathutils`` so that functionality
depending on :class:`rocketpy.mathutils.function.Function` does not leak into
generic utility modules such as ``rocketpy.tools``.
"""
from rocketpy.mathutils.function import Function
from rocketpy.mathutils.vector_matrix import Vector
def _pat_dynamic_helper(com_inertia_moment, mass, distance_vec_3d, axes_term_lambda):
"""Apply the PAT to inertia moments, supporting static and dynamic inputs."""
is_dynamic = (
isinstance(com_inertia_moment, Function)
or isinstance(mass, Function)
or isinstance(distance_vec_3d, Function)
)
def get_val(arg, t):
return arg(t) if isinstance(arg, Function) else arg
if not is_dynamic:
d_vec = Vector(distance_vec_3d)
mass_term = mass * axes_term_lambda(d_vec)
return com_inertia_moment + mass_term
def new_source(t):
d_vec_t = get_val(distance_vec_3d, t)
mass_t = get_val(mass, t)
inertia_t = get_val(com_inertia_moment, t)
mass_term = mass_t * axes_term_lambda(d_vec_t)
return inertia_t + mass_term
return Function(new_source, inputs="t", outputs="Inertia (kg*m^2)")
def _pat_dynamic_product_helper(
com_inertia_product, mass, distance_vec_3d, product_term_lambda
):
"""Apply the PAT to inertia products, supporting static and dynamic inputs."""
is_dynamic = (
isinstance(com_inertia_product, Function)
or isinstance(mass, Function)
or isinstance(distance_vec_3d, Function)
)
def get_val(arg, t):
return arg(t) if isinstance(arg, Function) else arg
if not is_dynamic:
d_vec = Vector(distance_vec_3d)
mass_term = mass * product_term_lambda(d_vec)
return com_inertia_product + mass_term
def new_source(t):
d_vec_t = get_val(distance_vec_3d, t)
mass_t = get_val(mass, t)
inertia_t = get_val(com_inertia_product, t)
mass_term = mass_t * product_term_lambda(d_vec_t)
return inertia_t + mass_term
return Function(new_source, inputs="t", outputs="Inertia (kg*m^2)")
# --- Public functions for the Parallel Axis Theorem ---
def parallel_axis_theorem_I11(com_inertia_moment, mass, distance_vec_3d):
"""Apply PAT to the I11 inertia term.
Parameters
----------
com_inertia_moment : float or Function
Inertia moment relative to the component center of mass.
mass : float or Function
Mass of the component. If a Function, it must map time to mass.
distance_vec_3d : array-like or Function
Displacement vector from the component COM to the reference COM.
Returns
-------
float or Function
Updated I11 value referenced to the new axis.
"""
return _pat_dynamic_helper(
com_inertia_moment, mass, distance_vec_3d, lambda d_vec: d_vec.y**2 + d_vec.z**2
)
def parallel_axis_theorem_I22(com_inertia_moment, mass, distance_vec_3d):
"""Apply PAT to the I22 inertia term.
Parameters
----------
com_inertia_moment : float or Function
Inertia moment relative to the component center of mass.
mass : float or Function
Mass of the component. If a Function, it must map time to mass.
distance_vec_3d : array-like or Function
Displacement vector from the component COM to the reference COM.
Returns
-------
float or Function
Updated I22 value referenced to the new axis.
"""
return _pat_dynamic_helper(
com_inertia_moment, mass, distance_vec_3d, lambda d_vec: d_vec.x**2 + d_vec.z**2
)
def parallel_axis_theorem_I33(com_inertia_moment, mass, distance_vec_3d):
"""Apply PAT to the I33 inertia term.
Parameters
----------
com_inertia_moment : float or Function
Inertia moment relative to the component center of mass.
mass : float or Function
Mass of the component. If a Function, it must map time to mass.
distance_vec_3d : array-like or Function
Displacement vector from the component COM to the reference COM.
Returns
-------
float or Function
Updated I33 value referenced to the new axis.
"""
return _pat_dynamic_helper(
com_inertia_moment, mass, distance_vec_3d, lambda d_vec: d_vec.x**2 + d_vec.y**2
)
def parallel_axis_theorem_I12(com_inertia_product, mass, distance_vec_3d):
"""Apply PAT to the I12 inertia product.
Parameters
----------
com_inertia_product : float or Function
Product of inertia relative to the component center of mass.
mass : float or Function
Mass of the component. If a Function, it must map time to mass.
distance_vec_3d : array-like or Function
Displacement vector from the component COM to the reference COM.
Returns
-------
float or Function
Updated I12 value referenced to the new axis.
"""
return _pat_dynamic_product_helper(
com_inertia_product, mass, distance_vec_3d, lambda d_vec: d_vec.x * d_vec.y
)
def parallel_axis_theorem_I13(com_inertia_product, mass, distance_vec_3d):
"""Apply PAT to the I13 inertia product.
Parameters
----------
com_inertia_product : float or Function
Product of inertia relative to the component center of mass.
mass : float or Function
Mass of the component. If a Function, it must map time to mass.
distance_vec_3d : array-like or Function
Displacement vector from the component COM to the reference COM.
Returns
-------
float or Function
Updated I13 value referenced to the new axis.
"""
return _pat_dynamic_product_helper(
com_inertia_product, mass, distance_vec_3d, lambda d_vec: d_vec.x * d_vec.z
)
def parallel_axis_theorem_I23(com_inertia_product, mass, distance_vec_3d):
"""Apply PAT to the I23 inertia product.
Parameters
----------
com_inertia_product : float or Function
Product of inertia relative to the component center of mass.
mass : float or Function
Mass of the component. If a Function, it must map time to mass.
distance_vec_3d : array-like or Function
Displacement vector from the component COM to the reference COM.
Returns
-------
float or Function
Updated I23 value referenced to the new axis.
"""
return _pat_dynamic_product_helper(
com_inertia_product, mass, distance_vec_3d, lambda d_vec: d_vec.y * d_vec.z
)
__all__ = [
"parallel_axis_theorem_I11",
"parallel_axis_theorem_I22",
"parallel_axis_theorem_I33",
"parallel_axis_theorem_I12",
"parallel_axis_theorem_I13",
"parallel_axis_theorem_I23",
]