Skip to content

Instantly share code, notes, and snippets.

@eufat
Last active April 25, 2017 06:29
Show Gist options
  • Save eufat/d9ae403e287e2d6d867b4893885b3b78 to your computer and use it in GitHub Desktop.
Save eufat/d9ae403e287e2d6d867b4893885b3b78 to your computer and use it in GitHub Desktop.
Frisbee Trajectory for KRAI
#include <stdio.h>
#include <math.h>
int main(){
double x;
//The x position of the frisbee.
double y;
//The y position of the frisbee.
double vx;
//The x velocity of the frisbee.
double vy;
//The y velocity of the frisbee.
double g = -9.81;
//The acceleration of gravity (m/s^2).
double m = 0.175;
//The mass of a standard frisbee in kilograms.
double RHO = 1.23;
//The density of air in kg/m^3.
double AREA = 0.0568;
//The area of a standard frisbee.
double CL0 = 0.1;
//The lift coefficient at alpha = 0.
double CLA = 1.4;
//The lift coefficient dependent on alpha.
double CD0 = 0.08;
//The drag coefficent at alpha = 0.
double CDA = 2.72;
//The drag coefficient dependent on alpha.
double ALPHA0 = -4;
//Calculation of the lift coefficient using the relationship given
//by S. A. Hummel.
double cl = CL0 + CLA * alpha * PI/180;
//Calculation of the drag coefficient (for Prantl’s relationship)
//using the relationship given by S. A. Hummel.
double cd = CD0 + CDA * pow((alpha-ALPHA0) * PI / 180 , 2);
//Initial position x = 0.
x = 0;
//Initial position y = y0.
y = y0;
//Initial x velocity vx = vx0.
vx = vx0;
//Initial y velocity vy = vy0.
vy = vy0;
double simulate(double y0, double vx0, double vy0, double alpha, double delta_t){
printf("Veamus KRAI TRUI 2017.");
printf("Frisbee Trajectory Simulation \n w/ initialized data.");
printf("y0: %d", y0);
printf("Vx0: %d", vx0);
printf("Vy0: %d", vy0);
printf("alpha: %d", alpha);
printf("delta_t: %d", delta_t);
printf("Running simulation ...");
bool simulation_flag = true;
i = 0;
while (simulation_flag){
// toggle flag if the iteration not the first and y is still real.
if (i != 0 && y <= 0){
simulation_flag = false;
}
//The change in velocity in the y direction obtained setting the
//net force equal to the sum of the gravitational force and the
//lift force and solving for delta v.
let deltavy = (RHO * pow(vx, 2) * AREA * cl / 2 / m + g) * delta_t;
//The change in velocity in the x direction, obtained by
//solving the force equation for delta v. (The only force
//present is the drag force).
let delta_vx = -RHO * pow(vx, 2) * AREA * cd * delta_t;
//The new positions and velocities are calculated using
//simple introductory mechanics.
vx = vx + delta_vx;
vy = vy + deltavy;
x = x + vx * delta_t;
y = y + vy * delta_t;
i++;
printf("x: %d \t y: %d \t %d iteration", x, y, i)
}
}
//initialize data at 0.
double y0 = 10.0;
double vx0 = 5.0;
double vy0 = 5.0;
double alpha = 30.0;
double delta_t = 0.001;
// run simulation.
simulate(y0, vx0, vy0, alpha, delta_t);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment