2

I'm writing a program that lets me animate the orbits of the planets in Matlab. This is working, but I would like to display the amount of times they fully went around the sun in a certain time lapse. I've been doing this by comparing the position they begin with with their current position: abs(current_position - begin_position < precision. But here's my problem: this precision is very different for each planet and their data. Like for Jupiter I have to set this precision to 0.2, while for Neptune it has to be 0.001, so I can't just say precision = 0.2, because it generates faults with my other planets if I do so. Is there another way to compare these numbers or another way to achieve this? I've been trying to use angles also, but that didn't worked out quite well.

Thanks in advance.

  • 2
    What about `abs(current_position/begin_position - 1) < precision` as now you could stick with a single precision as you are comparing them relatively? – Dan Apr 12 '13 at 15:53
  • Are their respective positions proportional to the precision? I.e. does a larger position correlate to a larger precision; if so than Dan's solution should work. If not then you could test each planet for their respective precisions and then store these values in a vector. – JustinBlaber Apr 12 '13 at 16:07

1 Answers1

0

I would use a vector to store the precision of each planet. However you will have to check in each iteration if the position match and then increase a counter for the number of orbits.

Why angles give you problems? You can accumulate the angle, subtract the initial angle and then calculate a modulus 360 (or 2*pi) to know the number of orbits.