Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Problem with a Sim

  1. Jul 7, 2010 #1
    Hello, I am attempting to make an orbital simulation for a final project in a computer science course. I have applied the inverse square law, and that seems to be working fine, but there is a problem with the vectors involved. I have the x component becoming negative when the particle's x value is greater than the sun's x value and vise versa for the y; but this configuration yields oblong orbits and sharp corners in the motion of the particle. The path of the particle ends up looking like a isosceles triangle, with the shorter side near the sun. If anyone knows the specific equations used in orbital simulators and can explain them, it would be much appreciated.
  2. jcsd
  3. Jul 7, 2010 #2
    You shouldn't need to be brute-forcing the equations like that, the force on a particle `i' should simply be
    \vec{F} = G\frac{m_i M}{r^3}\cdot r_x + G\frac{m_i M}{r^3}\cdot r_y + G\frac{m_i M}{r^3}\cdot r_z
    where the separation vector
    \vec{r} = \vec{R} - \vec{r}_i = (R_x - r_{i,x})\hat{x} + (R_y - r_{i,y})\hat{y} + (R_z - r_{i,z})\hat{z}
    For the star of mass 'M' and position 'R.'

    Does that help?

    Its hard to tell exactly what the problem you're having is based on just the triangular shape.
  4. Jul 7, 2010 #3
    It helps a lot, thank you. I am using those equations, so I know they are not the problem now. I think it might be a problem with the granularity of the monitor. I've been looking at other sims with the same parameters, and they appear to give the same result, just displayed smoother. I'm thinking about just switching my problem if I can work it out soon. I still have a week or so, so it will be fine. Thanks for your help though.
  5. Jul 8, 2010 #4


    User Avatar
    Science Advisor
    Gold Member

    Orbital simulations with more than two massive objects are incredibly difficult. It's called the 3 body problem.
  6. Jul 8, 2010 #5
    I disagree... from a simulation standpoint, there's really no difference between a two body problem and a three body problem, both are relatively trivial and can be performed on a laptop with very simple integration techniques (for 3-body euler's method would be fine, if a little slow).

    The only thing difficult about the three body problem is finding analytic solutions to arbitrary initial configurations--but that's explicitly impossible.
  7. Jul 8, 2010 #6
    Without seeing the code it's very hard to guess where the error is...i assume it's just some sort of typo error (y acceleration being changed instead of x, something like that)

    One thing you should always do for orbital simulations is to let conservation of energy fall back out of the code. That is, at every step, calculate the kinetic energy of both components, and the potential well between them...that should stay constant - if it doesn't, then there's something wrong with the simulation.

Share this great discussion with others via Reddit, Google+, Twitter, or Facebook