Help rearranging motion equations

Hey guys and gals, been a while since my last post.

First of all let me explain what I am trying to achieve: Threaded simulation

I have created a little 10 minutes program that calculates ballistic trajectories. From two user inputted variables, it will return how far the object went, and how long it was in flight.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
#include <cmath>

const double g = 9.81;

double square(double d)
{
    return d*d;
}
double DistanceTravelled(double a, double v)
{
    double sum = v*std::cos(a);     // Multiply velocity by Cosine(Angle)
    sum /= g;                       // Divide total by Gravitational Constant
    sum *= (v*std::sin(a)) + std::sqrt(square(v*std::sin(a)) + 2 * g * 0); // Some magic
    return sum; // Profit
}

double TimeTaken(double a, double v)
{
    double sum = v * std::sin(a); // Multiply velocity by launch angle
    sum += std::sqrt(square(v*std::sin(a)) + (2 * g * 0)); // Some magic
    sum /= g; // Divide by gravitational constant
    return sum; // profit;
}

int main()
{
    std::cout << "Angle of Launch: ";
    double angle;
    std::cin >> angle;
    std::cout << "Velocity of Launch: ";
    double velocity;
    std::cin >> velocity;
    double distance = DistanceTravelled(angle, velocity);
    std::cout << "Distance travelled: " << distance << " Meters.\n";
    std::cout << "Time taken: " << TimeTaken(distance,velocity) << "\n";
    return 0;
}


First of all are those two functions correct? A 45 Degree angle at 60M/s get's nearly 12 seconds of flight time. At a velocity of 100M/s it only has 5 seconds of air time according to these functions, is that normal? Seems a little strange to me.

Second of all, how would I rearrange this unfied formulae to calculate the objects distance at point (0 < dT < T)? In otherwords how would I simulate this objects movement?

I would like to spawn a thread, and have the thread update the user as trajectory time progresses. So if the trajectorys flight time is 12 seconds, the thread should be alive for those 12 seconds updating the console of the current objects distance away from launch.

I hope my question(s) make sense.

To re-iterate:

- Are those 2 functions correct?
- How do I simulate this motion?

Thanks in advance.
Hi,

Line 14 & 21 multiply by zero? Worked out v*std::sin(a) twice. Those formulae don't look anything like what I vaguely remember from high school bleems ago :+)

Could have separate functions for horizontal velocity and initial vertical velocity.

Distance is horizontal velocity * 2.0 * TimeToHighestPoint

Second of all, how would I rearrange this unfied formulae to calculate the objects distance at point (0 < dT < T)? In otherwords how would I simulate this objects movement?


Horizontal velocity is constant; vertical velocity changes: is it V0 - 1/2gt2 ?

Edit: The correct formula is V0t - 1/2gt2
Last edited on
Hi thanks for the reply,

Yes I feared they may have been wrong, I have tried copying wikipedias equations - https://en.wikipedia.org/wiki/Trajectory_of_a_projectile

If you could give me a good site to learn the mathematics behind this I would be grateful. :]

The zero's were place holders for the "inital height", 0 being the surface. It can be simplified so long as the initial height is 0 and the trajectory angle is 45 degrees.

As for vertical velocity changes, I couldn't tell ya. :P

Could you point me in the right direction for these equations?
Ah no worries, the wiki looks fine. Not for me to argue against that :+)

But you could use the simple formula. Time of flight uses the distance travelled value, and is d / (v *cos(theta) ).

The zero's were place holders for the "inital height", 0 being the surface. It can be simplified so long as the initial height is 0 and the trajectory angle is 45 degrees.


I see. Consider having that Y0 value as a variable. It's just that multiply by zero looks strange hard coded.

One more thing, your parameters to the functions should all be const

Could you point me in the right direction for these equations?


The equation I was thinking of (wrongly notated by me but fixed up now) is in the Uniform Acceleration section, Equation number 5.

https://en.wikipedia.org/wiki/Equations_of_motion#Uniform_acceleration
Last edited on
If you could give me a good site to learn the mathematics behind this I would be grateful. :]


The first two modules at:
https://www.khanacademy.org/science/physics
covers it pretty well.
Thanks for the help with the mathematics parts guys I appreciate it. I've looked into the Khan Academy link cire I am going through it now thanks for that. Been a long time since physics in college unfortunately.

Noted about the const correctness. I usually do this but due to the self containing nature of the equations I thought I could save myself some typing. :]

Any idea's about the simulation part? Am I going the right way about it trying to check certain conditions at point T time?
Topic archived. No new replies allowed.