# [Orbital] Gravity

This topic is 3313 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey all! :) I am wondering how to calculate gravity for a planet & have objects act accordingly. Basically, this is what I want to do: Have a few planets, for now lets just leave it at one. This planet has a mass of 20 (goes from 0-100). Then I have a asteroid. This asteroid should now be attracted by the planets gravity. However, this should be calculated in to a XVelocity and a YVelocity. ANd that part I am unsure of. Hope someone can help me out here, and if my post is not detailed/confusing than I will draw some pics to clarify. Thanks in advance! :)

##### Share on other sites
BEFORE edit

To calculate into a xvelocity and yvelocity, you would need to find the gravitational force that planet exerts, then find out the acceleration, and then apply the acceleration to the asteroid. The asteroid's velocity would then change.

AFTER edit

To calculate into a xvelocity and yvelocity, you would need to find the gravitational force that planet exerts, then find out the x and y components of the acceleration, then apply the acceleration components to the current velocity components.

##### Share on other sites
The problem here is, I do not know how to do these things. :-/

##### Share on other sites
http://en.wikipedia.org/wiki/Newtonian_Physics

##### Share on other sites
Hi there Pseudobot,

Playing around with gravity simulation is really fun, and I've done so for a couple of years :-) To help you along, here's a very small, well commented code sample demonstrating how to simulate gravitationally interacting objects on a computer. It's written in a language called freebasic which you might not know, but it's easily readable, and once you understand the principles behind it, you should be able to port it to whatever language you use.

http://www.jernmager.dk/stuff/freebasic/gravity_02.zip

good luck with it!

Cheers,
Mike

1. 1
Rutin
24
2. 2
3. 3
JoeJ
18
4. 4
5. 5

• 38
• 23
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631706
• Total Posts
3001833
×