Skip to content

Commit c2440f5

Browse files
authored
Correction of tools
Clean comments and clear code
1 parent 8598260 commit c2440f5

File tree

1 file changed

+56
-70
lines changed

1 file changed

+56
-70
lines changed

rocketpy/tools.py

Lines changed: 56 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
from cftime import num2pydate
2424
from matplotlib.patches import Ellipse
2525
from packaging import version as packaging_version
26+
from rocketpy.mathutils.function import Function
27+
from rocketpy.mathutils.vector_matrix import Vector
2628

2729
# Mapping of module name and the name of the package that should be installed
2830
INSTALL_MAPPING = {"IPython": "ipython"}
@@ -1019,131 +1021,115 @@ def wrapper(*args, **kwargs):
10191021
return decorator
10201022

10211023

1022-
# ######################################################################
1023-
# DÉBUT DU BLOC CORRIGÉ - THÉORÈME DES AXES PARALLÈLES (PAT)
1024-
# ######################################################################
1024+
10251025

10261026
def _pat_dynamic_helper(com_inertia_moment, mass, distance_vec_3d, axes_term_lambda):
1027-
"""
1028-
Helper interne pour gérer la logique dynamique/statique du PAT pour
1029-
les termes diagonaux (I11, I22, I33).
1030-
"""
1031-
# Importer localement pour éviter les dépendances circulaires
1032-
from rocketpy.mathutils.function import Function
1033-
from rocketpy.mathutils.vector_matrix import Vector
1027+
1028+
10341029

10351030
is_dynamic = (
1036-
isinstance(com_inertia_moment, Function) or
1037-
isinstance(mass, Function) or
1038-
isinstance(distance_vec_3d, Function)
1031+
isinstance(com_inertia_moment, Function)
1032+
or isinstance(mass, Function)
1033+
or isinstance(distance_vec_3d, Function)
10391034
)
10401035

10411036
def get_val(arg, t):
1042-
"""Obtient la valeur de l'argument à l'instant t."""
1037+
10431038
return arg(t) if isinstance(arg, Function) else arg
10441039

10451040
if not is_dynamic:
1046-
# Cas statique
1041+
10471042
d_vec = Vector(distance_vec_3d)
10481043
mass_term = mass * axes_term_lambda(d_vec)
10491044
return com_inertia_moment + mass_term
10501045
else:
1051-
# Cas dynamique : retourne une nouvelle Fonction
1046+
10521047
def new_source(t):
10531048
d_vec_t = get_val(distance_vec_3d, t)
10541049
mass_t = get_val(mass, t)
10551050
inertia_t = get_val(com_inertia_moment, t)
1056-
1051+
10571052
mass_term = mass_t * axes_term_lambda(d_vec_t)
10581053
return inertia_t + mass_term
10591054

10601055
return Function(new_source, inputs="t", outputs="Inertia (kg*m^2)")
10611056

1062-
def _pat_dynamic_product_helper(com_inertia_product, mass, distance_vec_3d, product_term_lambda):
1063-
"""
1064-
Helper interne pour gérer la logique dynamique/statique du PAT pour
1065-
les produits d'inertie (I12, I13, I23).
1066-
"""
1067-
# Importer localement pour éviter les dépendances circulaires
1068-
from rocketpy.mathutils.function import Function
1069-
from rocketpy.mathutils.vector_matrix import Vector
1057+
1058+
def _pat_dynamic_product_helper(
1059+
com_inertia_product, mass, distance_vec_3d, product_term_lambda
1060+
):
1061+
10701062

10711063
is_dynamic = (
1072-
isinstance(com_inertia_product, Function) or
1073-
isinstance(mass, Function) or
1074-
isinstance(distance_vec_3d, Function)
1064+
isinstance(com_inertia_product, Function)
1065+
or isinstance(mass, Function)
1066+
or isinstance(distance_vec_3d, Function)
10751067
)
10761068

10771069
def get_val(arg, t):
1078-
"""Obtient la valeur de l'argument à l'instant t."""
1070+
10791071
return arg(t) if isinstance(arg, Function) else arg
10801072

10811073
if not is_dynamic:
1082-
# Cas statique
1074+
10831075
d_vec = Vector(distance_vec_3d)
10841076
mass_term = mass * product_term_lambda(d_vec)
10851077
return com_inertia_product + mass_term
10861078
else:
1087-
# Cas dynamique : retourne une nouvelle Fonction
1079+
10881080
def new_source(t):
10891081
d_vec_t = get_val(distance_vec_3d, t)
10901082
mass_t = get_val(mass, t)
10911083
inertia_t = get_val(com_inertia_product, t)
1092-
1084+
10931085
mass_term = mass_t * product_term_lambda(d_vec_t)
10941086
return inertia_t + mass_term
1095-
1087+
10961088
return Function(new_source, inputs="t", outputs="Inertia (kg*m^2)")
10971089

1098-
# --- Fonctions Publiques pour le Théorème des Axes Parallèles ---
10991090

11001091
def parallel_axis_theorem_I11(com_inertia_moment, mass, distance_vec_3d):
1101-
"""
1102-
Calcule l'inertie I_11 (tangage) relative à un nouvel axe en utilisant le PAT.
1103-
Formule : I_11 = I_cm_11 + m * (d_y^2 + d_z^2)
1104-
"""
1105-
return _pat_dynamic_helper(com_inertia_moment, mass, distance_vec_3d,
1106-
lambda d_vec: d_vec.y**2 + d_vec.z**2)
1092+
1093+
return _pat_dynamic_helper(
1094+
com_inertia_moment, mass, distance_vec_3d, lambda d_vec: d_vec.y**2 + d_vec.z**2
1095+
)
1096+
11071097

11081098
def parallel_axis_theorem_I22(com_inertia_moment, mass, distance_vec_3d):
1109-
"""
1110-
Calcule l'inertie I_22 (lacet) relative à un nouvel axe en utilisant le PAT.
1111-
Formule : I_22 = I_cm_22 + m * (d_x^2 + d_z^2)
1112-
"""
1113-
return _pat_dynamic_helper(com_inertia_moment, mass, distance_vec_3d,
1114-
lambda d_vec: d_vec.x**2 + d_vec.z**2)
1099+
1100+
return _pat_dynamic_helper(
1101+
com_inertia_moment, mass, distance_vec_3d, lambda d_vec: d_vec.x**2 + d_vec.z**2
1102+
)
1103+
11151104

11161105
def parallel_axis_theorem_I33(com_inertia_moment, mass, distance_vec_3d):
1117-
"""
1118-
Calcule l'inertie I_33 (roulis) relative à un nouvel axe en utilisant le PAT.
1119-
Formule : I_33 = I_cm_33 + m * (d_x^2 + d_y^2)
1120-
"""
1121-
return _pat_dynamic_helper(com_inertia_moment, mass, distance_vec_3d,
1122-
lambda d_vec: d_vec.x**2 + d_vec.y**2)
1106+
1107+
return _pat_dynamic_helper(
1108+
com_inertia_moment, mass, distance_vec_3d, lambda d_vec: d_vec.x**2 + d_vec.y**2
1109+
)
1110+
11231111

11241112
def parallel_axis_theorem_I12(com_inertia_product, mass, distance_vec_3d):
1125-
"""
1126-
Calcule le produit d'inertie I_12 relatif à un nouvel axe en utilisant le PAT.
1127-
Formule : I_12 = I_cm_12 + m * d_x * d_y
1128-
"""
1129-
return _pat_dynamic_product_helper(com_inertia_product, mass, distance_vec_3d,
1130-
lambda d_vec: d_vec.x * d_vec.y)
1113+
1114+
return _pat_dynamic_product_helper(
1115+
com_inertia_product, mass, distance_vec_3d, lambda d_vec: d_vec.x * d_vec.y
1116+
)
1117+
11311118

11321119
def parallel_axis_theorem_I13(com_inertia_product, mass, distance_vec_3d):
1133-
"""
1134-
Calcule le produit d'inertie I_13 relatif à un nouvel axe en utilisant le PAT.
1135-
Formule : I_13 = I_cm_13 + m * d_x * d_z
1136-
"""
1137-
return _pat_dynamic_product_helper(com_inertia_product, mass, distance_vec_3d,
1138-
lambda d_vec: d_vec.x * d_vec.z)
1120+
1121+
return _pat_dynamic_product_helper(
1122+
com_inertia_product, mass, distance_vec_3d, lambda d_vec: d_vec.x * d_vec.z
1123+
)
1124+
11391125

11401126
def parallel_axis_theorem_I23(com_inertia_product, mass, distance_vec_3d):
1141-
"""
1142-
Calcule le produit d'inertie I_23 relatif à un nouvel axe en utilisant le PAT.
1143-
Formule : I_23 = I_cm_23 + m * d_y * d_z
1144-
"""
1145-
return _pat_dynamic_product_helper(com_inertia_product, mass, distance_vec_3d,
1146-
lambda d_vec: d_vec.y * d_vec.z)
1127+
1128+
return _pat_dynamic_product_helper(
1129+
com_inertia_product, mass, distance_vec_3d, lambda d_vec: d_vec.y * d_vec.z
1130+
)
1131+
1132+
11471133
# Flight
11481134
def quaternions_to_precession(e0, e1, e2, e3):
11491135
"""Calculates the Precession angle

0 commit comments

Comments
 (0)