Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

3. The Flight of a Ball: If we assume negligible air friction and the curvature

ID: 3607535 • Letter: 3

Question

3. The Flight of a Ball: If we assume negligible air friction and the curvature of the Earth, a ball that is thrown into air from any point on the Earth's surface will follow a parabolic Bight path. The height of the ball at any time t after it is thrown is given by: where so is the initial height of the ball, the = to sine is the initial velocity of the ball along y or vertical direction, and g is the acceleration due to gravity. The horizontal distance (range) travelled by the object is given by z(t) = Zo + trot where zo is the initial horizontal position and tro = to cos is the initial velocity of the ball along z or horizontal direction. Assume, that the intial velocity to 20 m/s at an initial angle . Calculate the values of range and height for angle between 0° and 90 in steps of 5°. Determine the angle that will result in maximum range for the ball. Plot the trajectory of the path for different angles in different colors

Explanation / Answer

#include<stdio.h>
#include<math.h>        // for sin and cos functions

#define g 9.8           // for gravitational constant g = 9.8 m/s2
#define PI 3.14159265

void compute_xy(double, double, double, double);

int main()
{
    double x0 = 0;          // initial horizontal position
    double y0 = 0;          // initial height of the ball
    double theta = 0;       // initial angle of throw
    double v0 = 20;         // initial velocity of the ball
    for(theta=0; theta<=90; theta=theta+5) // for loop to increase the value of theta by 5 deg in each loop
    {
        compute_xy(x0,y0,theta, v0);        // for each iteration the values of x and y for a particular theta value are computed and written to a file
    }
    return 0;
}

void compute_xy(double x_init, double y_init, double angle_in_deg, double vel_init) // this function takes the initial four arguments
{
    FILE *fp;                               // file pointer
    fp = fopen("xy_values.txt","a+");       // open a file in append mode
    double angle_in_rad = angle_in_deg * PI/180.0;      // convert angle in degree to radian since C sin and cos functions takes radian values
    double t = 0;                                       // time variable
    double y = y_init + ((vel_init * sin(angle_in_rad)) * t) - ((1/2) * g * t * t);     // calculate the value of height
    double x = x_init + ((vel_init * cos(angle_in_rad)) * t);                           // calculate the range
    t = t + 0.001;                                                                      // increase the time in steps of 0.001
    fprintf(fp,"Angle - %f %f %f ",angle_in_deg,x,y);                                 // write to file
    printf("Angle - %f %f %f ",angle_in_deg,x,y);                                     // print to console
    do{
        y = y_init + ((vel_init * sin(angle_in_rad)) * t) - ((1.0/2.0) * g * t * t);    // perform the operation in a loop
        x = x_init + ((vel_init * cos(angle_in_rad)) * t);
        t = t + 0.001;
        fprintf(fp,"%f %f ",x,y);
        printf("%f %f ",x,y);
    }while(y>0);                                                                        // check for the condition for end of loop by checking the height
    fprintf(fp," ");
    fclose(fp);                                                                         // close file
    return;
}

This is the program to find the various values of x and y for various angles. The values are found in the file xy_values.txt

The values can be plotted in MS Excel easily.

Please comment for any queries.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote