Skip to content

Commit 1898cb3

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 f427024 commit 1898cb3

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
@@ -689,8 +689,11 @@ def get_cp_position_from_alpha(self, alpha, mach):
689689
where CN(α) is the lift coefficient as a function of angle of attack
690690
and X_cp is the center of pressure position of each aerodynamic surface.
691691
"""
692+
# Threshold for numerical zero checks
693+
epsilon = 1e-10
694+
692695
# Handle edge case where alpha is effectively zero
693-
if abs(alpha) < 1e-10:
696+
if abs(alpha) < epsilon:
694697
return self.cp_position.get_value_opt(mach)
695698

696699
total_cn = 0.0
@@ -707,7 +710,7 @@ def get_cp_position_from_alpha(self, alpha, mach):
707710
total_cn += cn
708711
weighted_cp += cn * surface_cp
709712

710-
if abs(total_cn) < 1e-10:
713+
if abs(total_cn) < epsilon:
711714
return self.cp_position.get_value_opt(mach)
712715

713716
return weighted_cp / total_cn

rocketpy/simulation/flight.py

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

31283128
results = []
31293129
for i, t in enumerate(time_values):
3130+
# Convert angle of attack from degrees to radians
31303131
alpha_rad = np.deg2rad(aoa_values[i])
31313132
mach = mach_values[i]
31323133
sm = self.rocket.get_stability_margin_from_alpha(alpha_rad, mach, t)

0 commit comments

Comments
 (0)