/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
* trajectory.c
* Copyright (C) 2016 drdev
*
* trajectory is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* trajectory is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see .
*/
/*
Joshua Cooper and Anton Swifton, "Throwing a Ball as Far as Possible, Revisited,"
arXiv, November 8, 2016, https://arxiv.org/abs/1611.02376
This equation can be solved numerically (e.g., by the SageMath system [4]),
and has exactly one solution on the interval [0, π 2 ], which is approximately
0.9855 ≈ 56.47 ◦ . Assuming natural units, i.e., g = v = 1, the length of the
longest possible trajectory is 1.19967864 . . ., while π/4 yields a trajectory
of length 1.14779357 . . ., a more than 4.5% difference.
*/
#include
#include
#define pi 3.1415926535
#define g 9.80665
double x,y,y_old;
double angle,ang_rad;
double s,v,range;
double secant(double ang)
{
return 1/cos(ang);
}
double ds(double dx, double dy)
{
return sqrt((dx*dx)+(dy*dy));
}
int main()
{
x = 0.0;
y = 1.0;
y_old=0.0;
s=0.0;
v = 100.0;
angle = 45.0;
ang_rad = angle*pi/180;
//remove the next line to merely generate a trajectory at 45 degree angle
for (ang_rad = 0.01;ang_rad < 1.5;ang_rad = ang_rad+0.01)
{
s=0.0;
x = 0.0;
y = 1.0;
y_old=0.0;
while (y>=0)
{
y = (x*tan(ang_rad)) - (g*secant(ang_rad)*secant(ang_rad)*x*x/(2*v*v));
s = s + ds(1,(y-y_old));
//uncomment this line to get 45 degree trajectory data
//printf("%f\t%f\t%f\n", x,y,s);
x = x + 1;
y_old=y;
}
printf("%f\t%f\n", ang_rad,s);
s=0;
}
return (0);
}