# Need help programming an Orbital Simulator

• Big Big Ron
In summary: Anyway, it's not perfect, but it's a start.You might want to try using a leapfrog integration scheme to calculate the positions and velocities, and also look for an article on Verlet integration which may be a better option. I'm only going to have one planet orbiting a star, so I figured I would need to enter the mass of the star, the distance from the planet to the star, and also the initial velocity of the planet. From there I could go on to calculate the gravitational force acting on the planet, using F = G*M1*M2/r^2 , then find the acceleration of the planet using a = f/m. After that I can use
Big Big Ron

## Homework Statement

Hey, so basically I'm doing Advanced Higher Computing Science at school (It's a Scottish qualification), and I need to build an orbital simulator in VB.Net 2008 (nothing too fancy), but I'm having issues planning it all out. I'm only going to have one planet orbiting a star, so I figured I would need to enter the mass of the star, the distance from the planet to the star, and also the initial velocity of the planet. From there I could go on to calculate the gravitational force acting on the planet, using F = G*M1*M2/r^2 , then find the acceleration of the planet using a = f/m. After that I can use v = u + at to calculate the new horizontal and vertical velocities of the planet, then use them to find the new position of the planet, and then finally use the pen to draw it out. Is this approach any good? Some help of the structure of the program would be hugely appreciated, I'm not asking for the exact code, just some indication of the different methods and procedures I'll need to make it work. Thanks!:)

## Homework Equations

• Given that I know the new velocities, how would I find the new position of the planet? Could I use this equation : x2 = x1 + (Vx * t) I read it somewhere that this would be the way to do it, however I am unsure if it is correct.

3. Part 1 is kinda my attempt I guess.

I helped a friend program something similar for a physics course he took.

The way we approached it was quite similar. Single planet, single star (although it wouldn't be hard to scale this up to do multiples). Then we just used the basic physics formulas like you listed. The key thing to make your life easier is pick a deltaT to be your smallest time step. Then you don't have to get into processing integrals. I think we used an hour, but play around with it.

After we got it all programed, we needed data to try it out on. So we used the mass of the Earth and sun. Then the Earth's avg distance from the sun and its average orbital velocity as starting points, and... it didn't work. The planet kept flying off into the void. After a hour or so of trying to track down the issue, we finally clued in that the average distance and velocity didn't occur at the same time so our starting point was invalid. I guess my point is when you get something programmed and it doesn't work in this case it could be your code, or it could also be your starting data :) To get started plan out what data you'll need to keep for the orbiting objects, and how you'll store that info in the program.
Then how you'll go about actually calculating each step. 5min of planning can save your hours of coding

Let us know how it goes!

@Big Big Ron: That simple approach, used in a loop, will give some reasonable results for small time steps, but it suffers from the problem cpscdave mentioned: you accumulate errors in each time step. To make it worse, all errors go in the same direction, probably letting the planet leave the system over time. Try this first, once you get it running you can look for better approaches.

The method to calculate positions based on known accelerations or velocities is called integration scheme. The next-to-easiest algorithm is the leapfrog integration where you calculate velocities and positions at different steps. Verlet integration is even better. See also this overview article

Big Big Ron said:
I'm only going to have one planet orbiting a star, so I figured I would need to enter the mass of the star, the distance from the planet to the star, and also the initial velocity of the planet. From there I could go on to calculate the gravitational force acting on the planet, using F = G*M1*M2/r^2 , then find the acceleration of the planet using a = f/m. After that I can use v = u + at to calculate the new horizontal and vertical velocities of the planet, then use them to find the new position of the planet, and then finally use the pen to draw it out. Is this approach any good? Some help of the structure of the program would be hugely appreciated, I'm not asking for the exact code, just some indication of the different methods and procedures I'll need to make it work. Thanks!:)

Hi Ron,

I actually just made a simulation of the Earth orbiting the Sun in another program this past Saturday. It works. Sort of. Earth likes to spiral into the Sun after a few orbits before being shot out into intergalactic space, so I'm sure I messed up somewhere. I used:

A=F/M
V = Vo +At
X = Xo +Vt + 1/2At2
F = GM1M2/r2

Xo and Vo are "X-naught" and "V-naught" and represent the initial position and velocity at each time step.

I had to break the first 3 equations into into X and Y components using some trigonometry and then calculate each component. Steps in my program:
1. I first calculate the total force using the 4th equation.
2. I break the force into X and Y components based on the position of the planet relative to the star. (Tricky if you're not used to trigonometry like me)
3. Using each force component I find the acceleration in each axis.
4. Using the acceleration I find the change in velocity in each axis and then add the value to a variable called "X-Velocity" and "Y-Velocity" (See note in next step)
5. Using the acceleration and new velocity I calculate the change in position in each axis and add this change to variables "X-Position" and "Y-Position". (Basically I set Xo to zero, solve for X, which gives me a change in position in that axis, and then add this change to the variables. The same goes for the velocity in the previous step. I leave Vo as zero and solve for V using the acceleration)
6. Repeat.

I might have some of these steps in the wrong order, or be using the old/new values when I'm supposed to be using the other. I'm not sure yet. Hope this helps you get started.

Last edited:
berkeman
Wow! Thanks for great the help guys!:) I shall read about leapfrog integration tomorrow during school! These tips will definitely get me going in the right direction!

## 1. How do I get started with programming an Orbital Simulator?

To get started with programming an Orbital Simulator, you will need to have a basic understanding of programming languages such as Python or Java. You can also use existing software libraries or frameworks to help with the development process. It is also helpful to have a solid understanding of orbital mechanics and physics.

## 2. What are the main features and functions of an Orbital Simulator?

An Orbital Simulator is designed to simulate the motion of objects in space, taking into account factors such as gravity, velocity, and orbit. It can also calculate and display various orbital parameters and perform orbital maneuvers.

## 3. Are there any resources or tutorials available for learning how to program an Orbital Simulator?

Yes, there are many online resources and tutorials available for learning how to program an Orbital Simulator. You can also find books, forums, and online communities that can provide guidance and support for your project.

## 4. Can an Orbital Simulator be used for educational purposes?

Yes, an Orbital Simulator can be a useful tool for educational purposes, especially in fields such as aerospace engineering and astrophysics. It can help students understand complex concepts and visualize the motion of objects in space.

## 5. How can I test and validate the accuracy of my Orbital Simulator?

To test and validate the accuracy of your Orbital Simulator, you can compare its results with known data and calculations. You can also use real-world data from satellite missions or conduct experiments in a controlled environment. Collaborating with other programmers and experts in the field can also help improve the accuracy of your simulator.

• Classical Physics
Replies
7
Views
1K
• Astronomy and Astrophysics
Replies
12
Views
2K
• Engineering and Comp Sci Homework Help
Replies
7
Views
4K
• Sci-Fi Writing and World Building
Replies
18
Views
2K
• Introductory Physics Homework Help
Replies
18
Views
1K
• Classical Physics
Replies
2
Views
2K
• Engineering and Comp Sci Homework Help
Replies
2
Views
1K
• Engineering and Comp Sci Homework Help
Replies
2
Views
2K
• Engineering and Comp Sci Homework Help
Replies
15
Views
7K
• Electrical Engineering
Replies
2
Views
867