# My satellite should go in a circle, not an ellipse

1. Aug 31, 2011

### Rapidrain

I have been toying with a java programming project for a few months now. I want to
depict a satelite orbiting a planet (2 dimensional).

I've scaled down certain constants to fit the screen and have put GM (mu) at 200000 and
the distance from the gravitaional body, a planet, at 200 (pixels). Using the equations
where a perfect orbital velocity is equal to sqrt(GM/dist), I must have a velocity of
sqrt(1000) 31.62 pixels/sec to remain in a circle.

Problem is my model depicts an ellipse.

The distance starts at 200, drops down to nearly 150 halfway around and climbs up again
(!!!) to 200 when it reaches the starting point. This is better than crashing into the
planet or flying away in a straight line...but still it should be a "perfect" circle.

I could understand it if my crude iteration method made a consistently "too small" or
"too big" quantity and cause the satellite to slowly spiral into the planet and crash or
caused the satellite to slowly spiral away from the planet. However the satellite
creeps down and then creeps up in a single orbit. Very strange. Why the wobble?

Yes, I am moving in singular one second steps around the planet and complete the orbit
in about 24 steps. And yes, if I took infinitely small steps an infinite number of
times, instead of a finite number of iterations, then I would come out with a perfect
circle. I am not Isaac Newton though.

Can I compensate in any way? Multiply the vector magnitude by sqrt(1/pi) or something
like that? Tilt the initial velocity vector away from the planet by 1/distance degree or
something?

#### Attached Files:

• ###### Orbit with 1sec Iteration.jpg
File size:
16.6 KB
Views:
80
2. Aug 31, 2011

### HallsofIvy

Staff Emeritus
A general problem with iterations like this is "round off error". You are keeping only a limited number of decimal places and the error, unless you are very careful, can add up. That will result, eventually, not just in an ellipse rather than a circle but in a spiral that ends up going off to infinity.

3. Aug 31, 2011

### Rapidrain

Thanks HallsofIvy, I've thought about it, the fact that in some cases 1.0 is depicted as 0.9999999999. I'd like to understand however why any discrepency in accuracy leads to this yo-yo effect.

If my discrepency in accuracy lead 'a spiral that ends up going off to infinity' then okay. I'm happy. It's a discrepency with a uniform effect. Constantly moving away.

However the radius of the orbit goes down and then comes up again. Down and then up. This is not uniform. This is wierd.

But now I must sleep.

4. Aug 31, 2011

### Staff: Mentor

Where are you measuring the distance from? The image you included seems to have the sun at one of the foci of the ellipse, so if you're measuring the distance from the sun to the planet, and the planet is traveling in an elliptical orbit, then the distance should go up and down as you describe.

If I do some rough eyeball measurements using your drawing, it looks like the sun is located about 40 to 50 pixels to the right of the center of the ellipse. That would account for the discrepancy you are seeing in the distance.

5. Aug 31, 2011

### olivermsun

Can you show us code snippets or at least your algorithm?

6. Sep 1, 2011

### Rapidrain

to Mark44, I am measuring the distance from the center of the planet (sun, gravitational object). And I *know* it is travelling in an elliptical orbit. I want it to travel in a pure circular orbit. The planet in the center is *indeed* located 50 pixels off-center.

to olivermsun, okay.
I have two vectors.
The first is visible in the screen shot, going off to the right. That is my V-thrust vector. The spaceship fired his engines and attained a velocity of 31.62 which would generate a circular orbit--I wish.

The second is the V-grav caused by gravity after falling one second, calculated each time at the beginning of the interation as 1 sec*GM/(dist**2)

The iteration : In one second gravity at this point causes the object to fall towards the planet a certain distance and also causes the object to attain a downward velocity of V-grav.

The V-thrust vector causes the object to move to the right a certain distance in one second and retains this V-thrust velocity.

I move the object according to the two movements described above.

I give the object a *NEW* V-thrust vector = old-V-thrust + V-grav.
V-grav becomes zero again.

End of the iteration. I start again at this new position, about 14 degrees clockwise from the starting position. Adding the V-grav vector has tilted the V-thrust vector a bit downward.

I've added a screenshot of one single hop.

#### Attached Files:

• ###### HopOnce.jpg
File size:
23.6 KB
Views:
54
Last edited: Sep 1, 2011
7. Sep 1, 2011