Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions physics/ground_to_ground_projectile_motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
* @namespace physics
* @brief Physics algorithms
*/

// Define gravity as a constant within guidelines
constexpr double GRAVITY = 9.80665; // Standard gravity (m/s^2)


namespace physics {
/**
* @namespace ground_to_ground_projectile_motion
Expand All @@ -44,7 +49,7 @@ double degrees_to_radians(double degrees){
* @returns The time that the projectile is in the air for
*/
template <typename T>
T time_of_flight(T initial_velocity, T angle, double gravity = 9.81) {
T time_of_flight(T initial_velocity, T angle, double gravity = GRAVITY) {
double Viy = initial_velocity * (std::sin(degrees_to_radians(angle))); // calculate y component of the initial velocity
return 2.0 * Viy / gravity;
}
Expand All @@ -69,7 +74,7 @@ T horizontal_range(T initial_velocity, T angle, T time) {
* @returns The max height that the projectile reaches
*/
template <typename T>
T max_height(T initial_velocity, T angle, double gravity = 9.81) {
T max_height(T initial_velocity, T angle, double gravity = GRAVITY) {
double Viy = initial_velocity * (std::sin(degrees_to_radians(angle))); // calculate y component of the initial velocity
return (std::pow(Viy, 2) / (2.0 * gravity));
}
Expand Down