# Trajectory of a ball HELP

Posted 27 October 2019 - 11:57 PM

Hello;

I'm very new at coding in C language and i need help with the following assignment. So, i need to write a program that will calculate trajectory of a ball, but not analytically (with equations). I need to use definitions of position, velocity and acceleration and then use time derivative for x, y, z components for velocity and acceleration.
I should get trajectory of a ball with repeating these equations with small dt.

I wrote this code down below but it's completely wrong and i don't know how to rewrite it or find the mistakes. Any help would be very appreciated!

```#include <stdio.h>
#include <math.h>
#define g 9.81
#define PI 3.14

struct vektor
{
double x;
double y;
double z;

};

vektor distance (){
vektor p;
p.x = x + dx;
p.y = y + dy;
p.z = z + dz;
return p;
};

vektor velocity (){
vektor v;
//HItrosti
v.x = dr.x/dt;
v.y = dr.y/dt;
v.z = dr.z/dt;
return v;
};

vektor distanceII(){
vektor dr;
dr.x = v.x*dt;
dr.y = v.y*dt;
dr.z = v.z*dt;

};
vektor acceleration (){
vektor a;
a.x = dv.x/dt;
a.y = dv.y/dt;
a.z = dv.z/dt;
return a;
};

int main()
{
float v, a;

printf("Write initial velocity;");
scanf(" %f", &v);

printf("Write the angle  (degrees);");
scanf("%f", &a);

float T1,T2,T3;    //trajectory;
T1 = x;
T2 = y;
T3 = z;

for(dt=0;dt>=0;dt+=0.001)
printf("%f, %f, %f\n",T1,T2,T3);

return 0;

}
```

Is This A Good Question/Topic? 0

## Replies To: Trajectory of a ball HELP

### #2 modi123_1 • • Suitor #2
•    Reputation: 15363
• Posts: 61,613
• Joined: 12-June 08

## Re: Trajectory of a ball HELP

Posted 28 October 2019 - 07:18 AM

```62    for(dt=0;dt>=0;dt+=0.001)
63    printf("%f, %f, %f\n",T1,T2,T3);

```

I would figure your for loop needs some work to do what ever math functions you were looking for.

### #3 Skydiver Reputation: 7141
• Posts: 24,251
• Joined: 05-May 12

## Re: Trajectory of a ball HELP

Posted 28 October 2019 - 01:23 PM

Also, your various functions seem to be assuming the existence of variables that are not present. For example:
```vektor distance (){
vektor p;
p.x = x + dx;
p.y = y + dy;
p.z = z + dz;
return p;
};

```

You declared the variable p, but not the variables x, y, z, dx, dy, and dz. Chances are that the compiler is giving you undeclared identifier errors.

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }