Skip to content

Commit 581ad7a

Browse files
Address code review feedback
- Add comment explaining degrees to radians conversion in Flight.stability_margin - Replace magic number 1e-10 with named constant epsilon in get_cp_position_from_alpha Co-authored-by: Gui-FernandesBR <[email protected]>
1 parent 673f4d9 commit 581ad7a

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

rocketpy/rocket/rocket.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,8 +697,11 @@ def get_cp_position_from_alpha(self, alpha, mach):
697697
where CN(α) is the lift coefficient as a function of angle of attack
698698
and X_cp is the center of pressure position of each aerodynamic surface.
699699
"""
700+
# Threshold for numerical zero checks
701+
epsilon = 1e-10
702+
700703
# Handle edge case where alpha is effectively zero
701-
if abs(alpha) < 1e-10:
704+
if abs(alpha) < epsilon:
702705
return self.cp_position.get_value_opt(mach)
703706

704707
total_cn = 0.0
@@ -715,7 +718,7 @@ def get_cp_position_from_alpha(self, alpha, mach):
715718
total_cn += cn
716719
weighted_cp += cn * surface_cp
717720

718-
if abs(total_cn) < 1e-10:
721+
if abs(total_cn) < epsilon:
719722
return self.cp_position.get_value_opt(mach)
720723

721724
return weighted_cp / total_cn

rocketpy/simulation/flight.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3685,6 +3685,7 @@ def stability_margin(self):
36853685

36863686
results = []
36873687
for i, t in enumerate(time_values):
3688+
# Convert angle of attack from degrees to radians
36883689
alpha_rad = np.deg2rad(aoa_values[i])
36893690
mach = mach_values[i]
36903691
sm = self.rocket.get_stability_margin_from_alpha(alpha_rad, mach, t)

0 commit comments

Comments
 (0)