Ideas?

Pages: 12
May 13, 2009 at 11:59am
This isn't really a question like "How to xyz" or whatever, but it's still C++ related and a question, so, yeah:

I need some ideas for programs to do. I know about projecteuler, and I do use it, however I'd like something a little more physics based. Any ideas? Thanks in advanced. Also, more usable programs would be good - I can't see people going "Oooh! A program to find the 10001st prime! Brilliant! I shall download it at once!".

In short: I have no ideas for programs I can write. If anyone has any ideas, that would be good. Preferably physics based. Thanks in advance.
May 13, 2009 at 12:25pm
Write a program that can calculate, based on initial velocity, altitude, and direction (between -90 and 90) of a projectile, the following:
* The maximum altitude the projectile will reach.
* The horizontal distance from the original position when it lands.
* The final velocity (i.e. how hard it hit the ground).
* How long it took to land.
Assume:
* The projectile travels through a vacuum.
* The ground is a plane of arbitrary size.
* Gravity always pulls -90°-wards at 9.806 m/s^2, regardless of altitude and position.
If you want, add a weaker horizontal force (wind).
Last edited on May 13, 2009 at 12:34pm
May 13, 2009 at 12:26pm
autocad=chriscad or Mobile OS or Write a game maker else...
May 13, 2009 at 12:39pm
Collsion one sounds like fun. I'll give it a go.

Areyouupp; I'm not sure what you mean? What's this about "autocad"? Also, Mobile Phone OS? In a beginner forum? That does sound fun, but a little difficult. Anyway, I'll try the circle collision idea. Sounds fun, looks very challenging.
May 13, 2009 at 12:41pm
Remember that two circles collide when the distance between their centers is the same as the sum of their raidii.
May 13, 2009 at 12:43pm
omg. i'm so sorry.because My english is very bad.I'am trying learn english therefore I'dont understand your first message.Again sorry:(
May 13, 2009 at 12:49pm
If it's so bad, perhaps you shouldn't be posting, yet, mmh?
Learning a language takes many years, and if you try to use it when you're not ready yet, you'll just confuse yourself and others.
May 13, 2009 at 1:12pm
ok;)
May 13, 2009 at 2:35pm
Areyouupp, Helios is right - I'm learning German, I'm on my third year of learning it now, and I can still barely have a conversation. I'd be the guy going "Hello. My name is Chris. I am fourteen. What is your age? Where do you live?" etc. for about half an hour xD

I'm giving it a go on the circle things.

Can I just ask, what is -wards? Gravity pulls -90* (negative 90 degrees) toward the ground at 9.806 m/s^2. I'll take that m=mass and s=speed, so the mass of the object should be (9.806*mass/speed)^2;

I'm going to try it with classes. Should be a pretty steep learning curve, but I love a good challenge =]
May 13, 2009 at 2:46pm
http://en.wiktionary.org/wiki/-wards

m/s^2 is meters per second squared, or meters per second per second. It's a unit of acceleration and it means "the speed increases by x m/s every second". Since you wanted to do something with physics, I assumed you knew basic mechanics.

I'm going to try it with classes.
For the ballistics thing? Overkill. Can be done with a single struct to store the motion vector.
Last edited on May 13, 2009 at 2:47pm
May 13, 2009 at 2:59pm
aha.ok thanks;)I love this:D
May 13, 2009 at 5:33pm
Heh, I'm not that good at physics, I just love the subject.

As for -wards, you actually did mean it as a suffix for forwards, backwards, etc. I thought that, then decided it couldn't be right.

OH I just got it! You mean to say minus 90 degrees, then with the suffix of -wards after degress! Oh. Ok.

Then... by -90*-wards you mean the gravity is pulling the object downwards (that, I take it, is what you mean by -90*) at a 90 degree angle. Ok. I shall get to work on that.
May 14, 2009 at 6:08pm
I know this is virtually unreadable, but does this look about right so far:

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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*

/*
Symbols used:
G - Gravitational acceleration.
O - The angle at which the projectile is launched. Please note that O is a stand in for theta.
V - The initial velocity of the projectile.
Y - The starting altitude of the projectile.
D - The distance travelled by the projectile.
T - The time taken for the projectile to land.
F - The finishing velocity of the projectile.
H - The maximum altitude of the projectile.
*/

#include <iostream>
#include <cmath>

struct projectile_movement {
double g;
double O;
double v;
double y;
double d;
double t;
double f;
double h;
};

double findD(int i, int j, int m) { // d=(v*cos(O)/g)*(v*sin(O)+sqrt(v*sin(O)^2)+2gy)
projectile_movement distancetrav;
distancetrav.g=9.806; // The projectile will gain 9.806 m/s^2 from gravity.
distancetrav.O=i;    // The projectile will be launched at this angle (90*).
distancetrav.v=j;    // The projectile will be launched at this speed (10m/s).
distancetrav.y=m;    // The projectile will start at this altitude (10 metres).
distancetrav.t=0;     // So far the projectile has not moved.
distancetrav.d=((distancetrav.v*cos(distancetrav.O)/distancetrav.g)*
(distancetrav.v*sin(distancetrav.O+sqrt(distancetrav.v*sin(pow(distancetrav.O,2)))
+2*(distancetrav.g*distancetrav.y))));
// Thank you, C++, for your very easy structure access...
return distancetrav.d;
}

double findT(int i, int j, int m) { // t=(d/(v*cos(O)))
projectile_movement distancetrav;
distancetrav.g=9.806;
distancetrav.O=i;
distancetrav.v=j;
distancetrav.y=m;
distancetrav.d=findD(i, j, m);
distancetrav.t=(distancetrav.d/(distancetrav.v*cos(distancetrav.O)));
return distancetrav.t;
}

/*
double findF(int i, int j, int m) { // 
projectile_movement distancetrav;
distancetrav.g=9.806;
distancetrav.O=i;
distancetrav.v=j;
distancetrav.y=m;
distancetrav.d=findD(i, j, m);
distancetrav.t=findT(i, j, m);
distancetrav.f=?;
return distancetrav.f;
}

double findH(int i, int j, int m) { // 

}
*/

using namespace std;

int main() {
int i, j, m, n;
cout << "Enter angle of trajectory (between -90 and 90): ";
cin >> i;
cin.ignore();
cout << "\nEnter starting altitude: ";
cin >> j;
cin.ignore();
cout << "\nEnter starting velocity: ";
cin >> m;
cin.ignore();
cout << "Distance travelled by projectile: " << findD(i, j, m) << endl;
cout << "Duration of projectile flight: " << findT(i, j, m) << endl;
/* cout << "Finishing velocity of projectile: " << findF(i, j, m) << endl;
cout << "Maximum height the projectile could reach: " << findH(i, j, m) << endl; */
cin.get();
return 0;
}
Last edited on May 14, 2009 at 7:20pm
May 14, 2009 at 6:53pm
For God's sake, don't use single-letter identifiers.
g -> gravityForce
O -> 'theta' or 'initialAngle'
v -> initialSpeed
y -> initialAltitude
d -> distanceTravelled
t -> time
And use SI units!

Your design is very lacking. d and t are results, so they don't belong as properties in the struct. findD() should be a method.

Finally, you were supposed to simulate the movement of the projectile, not to find the results using a formula (which I'm not sure is right, anyway. http://en.wikipedia.org/wiki/Trajectory#Derivation_of_the_equation_of_motion ). Sure. Technically speaking, doing this is the right way, but it's definitely less fun. Physics simulations can be easily implemented using OOP.
May 14, 2009 at 7:27pm
Oh :l Misread the question...

Anyway, ok, I'll try actually simulating it.

By the way, I couldn't figure out (or find) a way to find the maximum height and finishing velocity. I'll change the identifiers to proper names. I have to admit, thinking about it, it makes more sense.

I'll keep trying. As I say, it's a learning curve for me. That's partially why I asked for the ideas - I was looking for a challenge. As a challenge, 'technically speaking' isn't 'correct', so I'll do it again (based off of what I've got now). Also, if by using OOP you mean for me to create a full GUI, that isn't happenig - I'm planning to start learning WIN32 API soon, but I'm not ready for that yet.

What library/header file would you recommend to draw the projectile (if the projectile were a circle)? I've heard of graphics.h but apparantly it is outdated. Are there any newer ones, or should I just use that, instead?
May 14, 2009 at 7:55pm
OOP: http://en.wikipedia.org/wiki/Object_oriented_programming

Why do you want to draw the projectile?
May 15, 2009 at 7:32am
Fun.

I'll put a refreshing distance counter, too. So it'll be like:

[start loop] [print current distance] [sleep 100ms] [clear screen] [end loop (when distance has not changed)]

example:

[code]
for (int i=0; i<x; i++) { /* where x is the distance that will be travelled, as calculated by the findD function */
// noticeably moving circle here
cout << "Distance travelled: " << /* variable holding distance travelled as per the time so far, i.e if the projectile had travelled for 20 seconds and would have reached 3.71m, then at 2 seconds it would have travelled 0.371m, so we keep going until the time of flight is correct */;
}

That's the kind of thing I mean anyway.
May 15, 2009 at 10:38am
Fun.
Alright, then. The SDL should be easy enough.
May 15, 2009 at 11:58am
Ok. Thanks.

I have these formulae:
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
double findDistance(double theta, double veloc, double alt) {
projectileMovement mov;

mov.initialAngle=theta;
mov.initialVelocity=veloc;
mov.initialAlt=alt;
mov.GravAcceleration=9.806;

double distTravelled=(mov.initialVelocity * cos(mov.initialAngle)/mov.GravAcceleration) *
                     (mov.initialVelocity * sin(mov.InitialAngle) +
                     (sqrt(pow(mov.initialVelocity * sin(initialAngle), 2)) +
                     (2 * (mov.GravAcceleration + mov.initialAlt));

return distTravelled;
}

double findFlightTime(double theta, double veloc, double alt) {

mov.initialAngle=theta;
mov.intitialVelocity=veloc;
mov.initialAlt=alt;
mov.GravAcceleration=9.806;

double distTravelled=findDistance();

double timeOf_Flight=(intitialVelocity * sin(mov.intitialAngle)) + 
                     (sqrt(pow(mov.initialVelocity * sin(initialAngle), 2)) +
                     (2 * (mov.GravAcceleration + mov.initialAlt));

return timeOf_Flight;
}


I shall make a function to animate a circle using those.
Last edited on May 15, 2009 at 12:12pm
May 15, 2009 at 2:34pm
 
(sqrt(pow(mov.initialVelocity * sin(initialAngle), 2))


Is that not pointless? You are are squaring a number that you then square root?
Pages: 12