Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

The 20 Line Challenge / Gravity and orbits

Author
Message
Algae Man
22
Years of Service
User Offline
Joined: 11th Nov 2002
Location: Canada
Posted: 31st Jul 2003 01:41
I made this program to help me better understand gravity and orbits and such. I especially wanted to understand how you can pull off a "gravity slingshot" manoeuvre. I never really understood that. For those who don't know what "gravity slingshot" is, it's a way of using a planet's (or star's) gravity to greatly accelerate a spaceship so that it flys off at incredible speed. This technique is described frequently in science fiction and was actually used for missions like Voyager (they used jupiter's gravity).

I treid to make this program as accurate as possible. What's surprising is how simple the mathematics are. All I really needed was one formula, provided for me so kindly by THE Sir Issac Newton. It is the formula for the force of attraction between two objects.

Controls:
you control the spaceship (the little line in the corner of the screen). The dot in the center is a planet.
arrowkeys control thrust and angle of the spaceship.

Ctrl points the spaceship towards the planet.
Spacebar resets the position of the spaceship.


Enjoy!

Feedback please.

P.S: Of course, if you remove the 'cls' at the end of the loop, the screen will not be erased every frame. Try removing it. The trails left by the spaceship are interesting.
Ocean Runner
21
Years of Service
User Offline
Joined: 18th May 2003
Location: United States
Posted: 31st Jul 2003 02:15
Interesting. You should try to make it so that you can set the planets gravity and therefore change how hard it is to escape the field.
Algae Man
22
Years of Service
User Offline
Joined: 11th Nov 2002
Location: Canada
Posted: 31st Jul 2003 02:28
You can alter the code to change the gravity.

in the lines:

vx#=newxvalue(vx#,atanfull((px#-rx#),(py#-ry#)),50*(1/((px#-rx#)*(px#-rx#)+(py#-ry#)*(py#-ry#))))
vy#=newzvalue(vy#,atanfull((px#-rx#),(py#-ry#)),50*(1/((px#-rx#)*(px#-rx#)+(py#-ry#)*(py#-ry#))))

Change the number '50' to whatever you want. It will change the strength of the gravitational field.
ReD_eYe
21
Years of Service
User Offline
Joined: 9th Mar 2003
Location: United Kingdom
Posted: 31st Jul 2003 11:34
its clever are you planning on using it in a game or converting it to 3d???

I have a website!!!
So go there: http://www.freewebs.com/darkb/index.htm
on second thought you probably shouldn't
Algae Man
22
Years of Service
User Offline
Joined: 11th Nov 2002
Location: Canada
Posted: 31st Jul 2003 21:46
When I started I had nothing in mind. I just wanted to make a program to accurately simulate orbits and slingshot effects. If I ever make a 3d space sim, I'll definately use accurate physics like in this program.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 31st Jul 2003 22:28
Thats nice.

I lowered the gravity, held down the control and up keys ... my very own spirograph!

Login to post a reply

Server time is: 2024-11-24 02:17:28
Your offset time is: 2024-11-24 02:17:28