Astrophysics/motion.c

48 lines
1.3 KiB
C

#include "motion.h"
#include <math.h>
/*
* Here, we calculate the initial speed
* Where alpha is the initial launch angle
* speed is the initial speed
* and c defined if we calculate for x or y
*/
double calculate_initial_speed(double alpha, double speed, const char c) {
// We calculated the v0 of x
if (c == 'x')
return speed * cos(alpha);
// Otherwise, we calculated the v0 of y
else
return speed * sin(alpha);
}
/*
* This function calcul the during of the time before the projectile have reach the ground
* Where v is the initial speed of xor y
* and grav is the gravitational force
*/
double calculate_delta_t(double v, double grav){
return (2 * v) / grav;
}
/*
* This function calcul the distance total of the projectile
* Where v is the initial speed of Vx
* and deltat is the result total time of flight
*/
double calculate_total_distance(double v, double deltat){
return v * deltat;
}
/*
* This function calcul the height max of the Projectile
* Where vx and xy are the initial speeds
* and grav is the gravitational force
*/
double calculate_height_max(double vx, double vy, double grav){
return (pow(vx, 2) - pow(vy, 2)) / (2 * -grav);
}
/*
* This function convert the degree in radian
*/
double degree_to_radian(double degree){
return degree * M_PI / 180;
}