Drawing a trajectory with multiple gravitational soures.

In summary, you are trying to figure out how to calculate a trajectory for an object, but you are struggling because the problem is too complicated. You need to find a way to calculate the trajectory step by step, and use an adaptive time step if needed.
  • #1
Nagransham
5
0
Hi there guys.

As the title implies I'm trying to draw a trajectory on the screen (yes, this is indeed about programing :P) involving multiple sources of gravity.

Here is my dilemma: Since I'm working with an update loop there would be no problem to just simulate an object and having it leave a trail. However it would have to travel the whole relevant distance in order to show the complete trajectory. This is problematic because the trajectory depents on input, so it has to be able to change instantly (as in a few ms / a single update) and needs to be drawn completely, instantly.

I found some formulas that looked promising, which seem to be able to do a lot of stuff with very little information and calculation, however I'm pretty sure i didn't find anything involving multiple sources of gravity. And frankly I'm not sure if there even is such a thing.

Luckily the only thing i need to make this work is the ability to find out where an object will be after a given time. And this, at least to me, sounds like it's far easier to do. Because then i can just play connect the dots and I'm ready to go.

Unfortunately I'm not really sure how to do this :/



So... i guess my question is this:

How could i figure out where a given object (providing it's starting position, velocity and direction) is after a given time, while beeing affected by multiple sources of gravity ?



Also: it's a little hard to figure out where to post this since it's math and also physics... so... if I'm totally off here, feel free to tell me.

I hope i was able to get my question across, since I'm terrible at talking about things i don't fully understand in the first place ;) Also english is not my native language, so show mercy :)
 
Technology news on Phys.org
  • #2
You need to find the trajectory step by step. There is no way around that for a general configuration with multiple sources. If the sources are fixed than I think a modern computer ought to be able to do it in a fraction of a second to a reasonable precision.
 
  • #3
Yea i figured as much. Now, the whole "connect the dots" thing is step by step :P

The problem is that it has to run on a phone and calculating and drawing all the steps every single update could become too much rather fast. I'm really worried about slower speeds, for example orbiting a planet far out. Because then, in order to show the whole path, i'd have to calculating insane amounts of steps. Of course for this particular scenario there are other solutions, but as soon as it stop beeing an orbit things get ugly.

I just hoped to find a way to skip a few steps withing each update without losing precision. Well i guess i could test it and see how much i can drop but I'm pretty sure it'll get out of hand rather quickly :/

Even expensive calculations can be worth it if i just have to do a few of them, so any non-ideal solution that might give this whole thing an edge can help.
 
  • #4
Use an adaptive time step. Short time steps when needed, long ones whenever possible. I'll try to dig out the formula used to determine the ideal time step. It's been a while since a last saw an algorithm that required an adaptive time step.
 
  • #5
One popular algorithm that uses an adaptive stepsize is Runge-Kutta-Fehlberg. Google for it. I used it several years ago to calculate gravitational trajectories in a Fortran program.

This is a general algorithm for solving differential equations numerically. To use it, you'll have to (a) set up a system of differential equations that basically says F = ma in vector form for the object that you want to "move," and (b) convert the resulting second-order differential equations into an equivalent set of first-order differential equations that you can encode into the RKF algorithm. I suspect there are some web sites out there with the details for exactly this problem.
 
Last edited:
  • #6
Runge Kutta Fehlberg is notoriously lousy for orbital mechanics. It oftentimes goes bonkers and yields ridiculously bad results.

A nice package that uses adaptive integration techniques (multiple such techniques; the integrator decides which is best) is the Livermore Solver for Ordinary Differential Equations, LSODE and its variants. You can get it from SourceForge (http://lh3lh3.users.sourceforge.net/solveode.shtml) or directly from Lawrence Livermore (http://computation.llnl.gov/casc/software.php ).

Another good integrator is Gauss-Jackson. This is a fixed step size integrator, but it is very good at orbital mechanics when the restrictions of a fixed step size are valid. Here's a simple MATLAB implementation: http://www.mathworks.com/matlabcent...ckson-eighth-order-ode-solver-fixed-step-size.
 
Last edited by a moderator:
  • #7
I'm impressed. Not only does one actually get an answer here (this goes out to pretty much every other physics forums i ever visited) but you guys are fast too.

Not only that but now you show knowledge in programing too. Cool.

Anyway, i'll need some time to dig through that. Thanks for the keywords and links guys, that's probably the best solution there is, at least i can't imagine it getting better.

Now, i'll look into all of that and if i mess up i'll be back :P
 
  • #8
I agree with D F that if you're looking for precision, RKF isn't the way you want to go, except maybe as a first version that you can easily upgrade to a better algorithm if you set up the interface properly between the differential-equation-solver and the rest of your program.

As I recall, in my old program I could watch planetary orbits slowly spiral inwards towards the sun, because the errors in the RKF algorithm tended to decrease the overall energy of the system. (Or maybe the error was in the other direction, and the orbits spiraled outwards? It was a long time ago.)
 
  • #9
Well it's just for drawing a trajectory, the actual objects will be simulated. So if the error margin is small enough it won't matter all that much. But then again, slow passages might become a problem since you'd need a rather small time step and hence many calculations and that could then add up to visible errors in the trajectory.

That said, i didn't have time to look into either of the suggested things, so feel free to ignore my blabbering :)
 
  • #10
Well... i took some time and looked into the links and infos you guys provided and I'm not really sure on how helpful those are. Mostly because I'm not understanding any of it :|

I looked into that mathlab implementation you linked me and I'm afraid it'll take me a week to even understand what the code does...

Looks like i really have to refresh my math, huh ?
 

1. How do multiple gravitational sources affect the trajectory of an object?

Multiple gravitational sources can affect the trajectory of an object by altering its path and velocity. The object will experience a combined gravitational force from all sources, causing it to deviate from its original trajectory.

2. How do you calculate the trajectory of an object with multiple gravitational sources?

To calculate the trajectory of an object with multiple gravitational sources, you can use the principle of superposition. This involves adding the gravitational forces from each source to determine the net force on the object. You can then use this net force to calculate the object's trajectory using Newton's laws of motion.

3. Can an object's trajectory be influenced by more than two gravitational sources?

Yes, an object's trajectory can be influenced by an unlimited number of gravitational sources. As long as there is a net gravitational force acting on the object, it will experience a change in trajectory.

4. How does the distance between gravitational sources affect an object's trajectory?

The distance between gravitational sources can have a significant impact on an object's trajectory. The closer the sources are to each other, the stronger the combined gravitational force will be, resulting in a greater deviation from the original trajectory. On the other hand, if the sources are further apart, their individual gravitational forces may cancel each other out, resulting in a less significant change in trajectory.

5. Can objects with different masses be affected differently by the same gravitational sources?

Yes, objects with different masses can be affected differently by the same gravitational sources. This is because the gravitational force experienced by an object is directly proportional to its mass. Therefore, an object with a larger mass will experience a stronger gravitational force and may have a different trajectory compared to an object with a smaller mass.

Similar threads

  • Programming and Computer Science
Replies
1
Views
982
Replies
9
Views
1K
  • Programming and Computer Science
Replies
4
Views
323
  • Programming and Computer Science
Replies
1
Views
587
  • Programming and Computer Science
Replies
1
Views
978
Replies
2
Views
700
  • Special and General Relativity
Replies
17
Views
1K
Replies
2
Views
757
Replies
1
Views
783
  • STEM Academic Advising
Replies
13
Views
852
Back
Top