# An orbiting body adding velocity vectors.

Rapidrain
Just for fun I put together a java app which traces the flight path of an object and it's reaction in the neighbourhood of a gravitational object.

The object flies in an odd trajectory so I think I have my head on backwards with some newtonian concepts.

I have the object initially near a gravitational object (a planet). I have one vector pointing towards the planet at all times with a value proportional to BigNumber/(distance)**2. This is vector velGS.

A second vector is called velThrust and gives the object an initial velocity at right angles to the gravity vector. (at right angles to it, but only initially because the object follows a curve)

The vectors velGS and velThrust added together form the vector velSum.

velSum defines the trajectory of the object.

Something is wrong because it traverses a 90' angle and at the point where velGS and velThrust point in opposite directions it either escapes or crashes into the planet. Seems odd to me. I thought a crash would entail spiralling downward.

must velThrust change its direction during the first 90' because of the gravitational force?

or

must velThrust maintain its direction at all times? // conservation of momentum, right?

I've added some jpgs to show what this guy is doing.

Attatched are screen shots of the initial configuration :
Green line = velThrust
Red line = velGS
Blue line = velSum = velGS + velThrust

and an escape trajectory where velThrust = 30
and a crash trajectory where velThrust = 25.

#### Attachments

Gold Member
Are you using the arctangent (atn or atan) function anywhere in your code? If so, you need to add some piecewise logic since it doesn't know what quadrant you're inputting. For example atn(-1/ -1), you would like it return 225 degrees, since the point -1,-1 is in the 3rd quadrant. But -1/-1 = +1, so it returns you 45 degrees instead.

It might be more proper to call your red vector acc since it is an acceleration, not a velocity. Change in velocity is acceleration times time, so what you are really adding to the vector you call velThrust is (acceleration * time).

You might also want to rename velThrust since it is simply a velocity vector. Thrust is a force. The way you've named your variables makes it seem like you're adding a velocity to a force to get a new velocity.

Rapidrain
What's in a name, a vector by any other name would...

Not to worry Tony. The thing happens in all four quadrants. The arctangent is not a problem. The program DOES know which quadrant it is in. I battled that beast a while back already.

The mere renaming of components of the programm is not the kind of answer I am seeking. I am actually looking to find if the velThrust vector must be rotated to remain at right angles to the gravitational field at all times since it initiated at right angles to the gravitaional field.

Does a force and a change in the direction of a force on an object modify the direction of momentum of the object?

That's the question I have.

Gold Member
I understand that renaming the variables won't solve your problem. It was simply a suggestion to make it easier for you to discuss your code with others. For example, in this post, you've asked a question about velThrust. I needed to re-read your OP to see what this was, which I would not have had to do if you had simply named it vel.

Your velocity does not need to be reoriented to a right angle with the gravity field. In an elliptical orbit, your velocity will only be perpendicular to the gravity field at aphelion and perihelion.

Yes, the direction of your momentum will be continuously modified. p=mv, where v is a velocity with a speed and direction. At no point is your satellite travelling in a straight line, so its direction is always changing. Hence its velocity and momentum vectors are always changing.

Your basic logic should look something like this:

1. Initialize position and velocity vectors. Since you're initially making your velocity vector perpendicular to the gravitational field, you satellite begins the simulation at either aphelion or perihelion, depending on whether your velocity is greater than or less than circular orbital velocity for that distance.

2. Compute acceleration vector. First you must compute distance using the pothagorean theorem on the components of your position vector. Then use a=GM/r^2.

5. Go to step 2

Rapidrain
Since you're initially making your velocity vector perpendicular to the gravitational
field, you satellite begins the simulation at either aphelion or perihelion, depending on
whether your velocity is greater than or less than circular orbital velocity for that
distance.

If I find myself 100 km above a planet and I fire the rocket engine for a moment
perpendicular to the g-field to induce a velThrust of 6 km/second then

velGS ...the velocity vector caused by g in the first second, 9.8 km/sec
+ velThrust ...the velocity vector my rocket engine caused, 6 km/sec
--------------------------------------------------------------------------------
= velSum : 11.49 km/sec (thanks to Mr. Pythagorus)
pointed downwards towards the planet at an angle of 58.51 degrees to the horizontal

and this is automatically aphelion or perihelion?

Sounds more like a crash landing!

You're right, the red arrow is depictive of the acceleration but acceleration implies a velocity and this red arrow in my model shows the velocity caused by the acceleration towards the planet. Its magnitude and direction depicts the velocity the gravitational field gives to the object.

The gravitational field imparts a velocity and my rocket engine imparts a velocity on the object.

And if I want to depict the result of all factors (my rocket engine and the planet) then I must add two vectors of velocity, not an acceleration vector and a velocity vector. (My math teachers would have had me shot.)

One thing I haven't made clear here -- I add the two vectors together every half second. The whole model goes in hops. Each time I recalculate the direction and magnitude of the velGS and leave the velThrust as it was. (must I alter the direction of velThrust??) Then I add them together again to determine velSum and this shows which direction and how far the next hop will take me.

And something else I haven't made clear -- velThrust is a component of the movement of the object. Not the full end result.

Question : does the g-field change the direction of my velThrust vector? Slowly I am thinking that yes, it does. However I need someone to answer why.

Last edited:
Gold Member

If I find myself 100 km above a planet and I fire the rocket engine for a moment
perpendicular to the g-field to induce a velThrust of 6 km/second then

velGS ...the velocity vector caused by g in the first second, 9.8 km/sec
+ velThrust ...the velocity vector my rocket engine caused, 6 km/sec
--------------------------------------------------------------------------------
= velSum : 11.49 km/sec (thanks to Mr. Pythagorus)
pointed downwards towards the planet at an angle of 58.51 degrees to the horizontal
Your g is rather strong. 100 km above Earth, the acceleration due to gravity is a=GM/r^2 = 6.67e-11*5.97e24/(6378000 + 100000)^2 = 9.49 meters per second per second. So after (1/2) second (you said you were taking half second jumps), your velocity would be 6 km/s tangential and 0.00949 km/s radial. That's virtually perpendicular to the ground.
and this is automatically aphelion or perihelion?
It's no longer aphelion or perihelion, as that happened 1/2 second ago, because as you stated in your OP,
A second vector is called velThrust and gives the object an initial velocity at right angles to the gravity vector. (at right angles to it, but only initially because the object follows a curve)

Sounds more like a crash landing!
Yes, if you're at an altitude of 100 km, travelling 6 km/s around a planet whose gravity is strong enough to accelerate you by 9.8 kilometers per second, you'll be on the ground very quickly.

And if I want to depict the result of all factors (my rocket engine and the planet) then I must add two vectors of velocity, not an acceleration vector and a velocity vector. (My math teachers would have had me shot.)
Yes, that's why I told you
Change in velocity is acceleration times time, so what you are really adding to the vector you call velThrust is (acceleration * time).
You can't add acceleration to velocity and get anything meaningful. But you can add (acceleration * time) to velocity because (acceleration * time) is a velocity. Look a the units: (m/s^2) * s = m/s. In this case, the * time is very important because you're adding your vectors every half second.

Question : does the g-field change the direction of my velThrust vector? Slowly I am thinking that yes, it does. However I need someone to answer why.
If I understand your variable names correctly, velThrust is your delta V caused by rocket engines on your spacecraft. The g-field has no control over this. You can point your spacecraft in any direction you like prior to firing your engines.

So if you are taking time steps of 1/2 second, your logic becomes:
velSum = velSum + velGS + velThrust
where velGS is (GM/r**2) * (1/2).
The 1/2 is important since your deltaV is your acceleration (GM/r**2) times the length of time you spent accelerating.

Other things to keep in mind:

It is important to keep units consistent. The gravitational constant is usually express as 6.67E-11 m^3/(kg s^2). So if this is the value you're using for G, make sure you're using meters and meters / second rather than kilometers and kilometers / second.

The r in your formula is not distance to the surface of the planet, rather it is distance to the center of the planet.

Don't continuously fire your rocket engines (velThrust), or you'll build up huge velocities. During most (1/2) second time steps, your velThrust should be 0, unless you're intentionally trying to alter the shape of your orbit.

How do you update velocity and position?

Rapidrain
How do you update velocity and position?

As I said, I've got two vectors, velThrust, a velocity induced by a short belch from the engine of the rocket and I've got velGS, the velocity induced by a Gravity Source ( a planet ). This second one is also an accelleration, as Tony pointed out.

In the last week I've changed a bit of my computing philosophy. I start at a position and add both velThrust and velGS together to form the vector velSum. Taking a short time interval I can add velSum*(short time period) to the initial position and there I have my new position.

The big change is that I recalculate what velGS is at the new position and !!!! I let velThrust for this next iteration = velSum from the last iteration. Why? Because the accelleration from the gravity field changed the direction and magnitude of the initial velocity vector (velThrust). Earlier I had not allowed velThrust to be modified and that led to curly-Q trajectories.

And to Tony, have no fear about my lack of elaborate numericals. This is a model. I am actually dealing with pixels per second, not meters, miles or leagues. I mean, can you imagine being in an orbit around the earth at a height of 200 pixels?

Just the other day I let GM = 900 and it really helped in modelling the movement of an object in a circular orbit around a planet. Of course in the real world circular orbits are nearly impossible but this is a mathematical model. First a circle then an ellipse.

the acceleration due to gravity is a=GM/r^2 = 6.67e-11*5.97e24/(6378000 + 100000)^2 = 9.49 meters per second per second.
comes later.

And rest assured, I know the difference between km and meters.

Homework Helper
What your trying to do requires numerical integration. For each time step, you calculate

new_velocity = old_velocity + time_step x average_acceleration

One way to do this is to use trapezoidal method

average_accleration = 1/2 (acceleration0 + acceleration1)

where acceleration0 is the acceleration at the start of a time step and acceleration1 is the acceleration at the end of a time step.

Rapidrain
thanks rcgldr,

that is exactly what I have been looking for.

Just this afternoon I discovered that using an r = 6.37 e06 meters (earth radius) and earth mass (5,97E+024 kg), the circular orbit velocity should be 7908 m/s. When the ship travels that distance on a straight line for one second, it comes away from the surface of the earth 4.9 meters--which is the distance something falls at the surface of the earth in one second. I was fretting about which direction to set the 4.9 meter fall in--i'm such a stickler--until you mentioned the trapezoidal process.

Quite a splinter of a triangle that...0.0006207384 radians in all.

Since you mentioned that trapezoidal process of adding the distance vectors I can now stop worrying about the veracity of my assumptions.

many thanks.

Homework Helper
Since you mentioned that trapezoidal process of adding the distance vectors.
You can calculate distance (position) once you calculate the new velocity, using the same method:

new_position = old_position + time_step x 1/2 x (old_velocity + new_velocity)