Documents projectile launch angle formula

Adds a comment documenting the formula used for calculating the projectile launch pitch angle.

The comment includes a link to the Stack Overflow discussion where the formula was found and the LaTeX representation of the formula for clarity.
This commit is contained in:
2025-07-31 21:51:52 +03:00
parent 231ef35a0a
commit 4b44ce0667

View File

@@ -28,6 +28,18 @@ namespace omath::projectile_prediction
const float m_maximum_simulation_time; const float m_maximum_simulation_time;
const float m_distance_tolerance; const float m_distance_tolerance;
// Realization of this formula:
// https://stackoverflow.com/questions/54917375/how-to-calculate-the-angle-to-shoot-a-bullet-in-order-to-hit-a-moving-target
/*
\[
\theta \;=\; \arctan\!\Biggl(
\frac{%
v^{2}\;\pm\;\sqrt{\,v^{4}-g\!\left(gx^{2}+2yv^{2}\right)\,}
}{%
gx
}\Biggr)
\]
*/
[[nodiscard]] [[nodiscard]]
std::optional<float> std::optional<float>
maybe_calculate_projectile_launch_pitch_angle(const Projectile& projectile, maybe_calculate_projectile_launch_pitch_angle(const Projectile& projectile,