Sign in to follow this  
pseudobot

[Orbital] Gravity

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 this post


Link to post
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 this post


Link to post
Share on other sites
To find the force exerted on the asteroid use Newton's law of universal gravitation.
To find the acceleration of the asteroid towards the planet use Newton's second law of motion.
To find the new velocity (given the old velocity and the amount of time that has passed since the last frame) use the first SUVAT equation.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this