# Trajectory of a ball HELP

Page 1 of 1

## 2 Replies - 267 Views - Last Post: 28 October 2019 - 01:23 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=417685&amp;s=9d9fdd7b46a5461b2234ed0681789e43&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

Reputation: 0
• Posts: 1
• Joined: 27-October 19

# 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: 15359
• Posts: 61,598
• 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

• Code herder

Reputation: 7139
• Posts: 24,245
• 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.