2 Replies - 267 Views - Last Post: 28 October 2019 - 01:23 PM Rate Topic: -----

#1 spqwnrad   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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   User is online

  • Suitor #2
  • member icon



Reputation: 15359
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#3 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7139
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1