(simple) motion of a projectile

Hello guys,
I have been staring at this piece of code (the complete program) trying to figure out why it's not working!
It gives a (very) funny output. why?? it's so simple. It should work (even if my PI approximation is crap)
Please help me!! :(

Edit: forgot to say, the program simply outputs in 4 columns X,Y and T at 200 points from 0 degrees to 90 degrees.


double get_X(int in_vel, double angle)  //horizontal range
{
       double X=0;
       const double g=9.801;
       X=(in_vel)*(in_vel)*(sin(2*angle))/g;
    
       return X; 
 }
 
double get_Y(int in_vel, double angle)   //maximum height reached
{
       double Y=0;
       const double g=9.801;
       Y=(in_vel)*(in_vel)*((sin(angle))*(sin(angle)))/2*g;
    
       return Y;
 }
 
double get_T(int in_vel, double angle)      //time to reach that height
{
       double T=0;
       const double g=9.801;
       T=(in_vel)*(sin(angle))/g;
    
       return T;
 }

int main()
{
    double angle=0;
    double in_vel=10;
    
    for (int i=0;i<200;i++)
    {

        cout<<get_X(angle,in_vel)<<" "<<get_Y(angle,in_vel)<<" "<<get_T(angle,in_vel);
        cout<<"\n";
        
        angle=angle+(3.14/400);
    }

    _getch();
    
return 0;
}
Last edited on
I kind of solved it.
Now it works fine and the outputs are all different.
Still, the values are too small. There is something that still needs to be fixed.



double get_X(double in_vel, double angle)
{
       double X=0;
       const double g=9.801;
       X=(((in_vel)*(in_vel))*sin(2*angle))/g;
    
       return X; 
 }
 
double get_Y(double in_vel, double angle)
{
       double Y=0;
       const double g=9.801;
       Y=(in_vel)*(in_vel)*((sin(angle))*(sin(angle)))/2*g;
    
       return Y;
 }
 
double get_T(double in_vel, double angle)
{
       double T=0;
       const double g=9.801;
       T=(in_vel)*(sin(angle))/g;
       
       return T;
 }

int main()
{
    double angle=0;
    double in_vel=10;
    
    for (int i=0;i<200;i++)
    
    {
        cout<<i+1<<"        ";
        cout<<get_X(angle,in_vel)<<"        ";
        cout<<get_Y(angle,in_vel)<<"        ";
        cout<<get_T(angle,in_vel);
        cout<<"\n";
        
        angle=angle+(3.14/400);
    }

    _getch();
The issue is in here, I think:


double get_X(double in_vel, double angle)
{
       double X=0;
       const double g=9.801;
       X=(in_vel*in_vel)*sin(2*angle)/g;
    
       return X; 
 }


Can anybody spot any mistake?
When you call those functions, you seem to be supplying the arguments in the wrong order.
OMG, I love you.

Yes you are perfectly right. And now everything works perfectly.
Thank you so much.
Topic archived. No new replies allowed.