Simulation: two body system

Here is a brief description of a two body solar system I made.

This simulation consists of a star placed at one of the foci of the elliptical orbit of the planet. The planet’s motion has been plotted according to its equation of the elliptical orbit which can be derived given its eccentricity and length of major axis. The celestial objects are not drawn according to the actual size, mass and rotation period since the derived orbital equation already takes care of it.

Here, I have used openGL to simulate the result where the eccentricity of the object is 0.0934 and the length of semi major axis is 1.524 units. Thus the equation of ellipse becomes:

(x/1.524)2 + (y/1.517)2 = 1


//This part updates the ordinate of the celestial body.


//this part checks if the abscissa has exceeded the permitted value and if so, updates it.

if(xcoord>=1.524 && flag==0)




if(xcoord<=-1.524 && flag==1)




The spheres of two bodies can be drawn by

glutWiredSphere(radius, latitudes,longitudes)

where radius, latitudes and longitudes depend on the celestial body.

Since one of the body remains at foci and other one revolves around it, the second body’s position can be updated using:


and the rotation can be shown as:

glRotatef(rot,0.0f,xcoord/2,0.0f); //assuming orbital inclination is zero and a rotation period rot.

Another good approach to do the same thing would be to draw the simulation using the gravitational and Kepler’s laws instead of calculating the trajectory of the planet’s motion

The video can be viewed at :

You can view my other video at:

img1 img2 img3


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s