| Thread Closed |
Create an Orbital Simulator |
Share Thread | Thread Tools |
| May3-08, 06:45 PM | #18 |
|
Mentor
Blog Entries: 10
|
Create an Orbital Simulator |
| May3-08, 07:48 PM | #19 |
|
|
I found a simulator here: http :// kornelix . squarespace . com / galaxy /
(it seems I don't have URL priviledge, but google on "stellar simulation") It runs under Linux so I fired up that computer and installed it. It runs well, but not much in the way of features. I haven't reviewed the code closely, but it seems to just use the F=MA type of approach. If I can get version 1.0 running, then I can look into better accuracy for close approaches. There are two primary segments of this projects Calculating the positions Displaying the field In this forum I want to discuss the calculations. What type of coordinate system would be best, polar, Cartesian, or something else I don't know about? It seems to me that Cartesian would be better. If for no other reason, I have never messed with polar coordinates. But if polar would be much better, I would like to know. If Cartesian, I suspect that it would be easier to deal with if the origin is in one of the corners rather than in the middle. My first thought would be the lower left corner. Thoughts about selecting the range: Astronomical Units, millions of miles, something else? BTW: This site seems to respond much faster under Linux with Firefox than under XP with IE-7. |
| May3-08, 09:09 PM | #20 |
|
|
I hope I didn't PO lonedragon excessively... |
| May3-08, 09:26 PM | #21 |
|
Mentor
Blog Entries: 10
|
bkelly,
In Cartesian coordinates it's easier to convert from the (x,y) calculated positions to displayed pixel locations, as only simple scaling factors are involved. Might also be easier to put the origin at pixel (0,0) in the display in the upper left, but if you don't it's still pretty straightforward to rescale from (x,y) to pixel location. I remember an algorithm a former physics teacher gave me. Better than Euler, not as accurate as Runge-Kutta, but pretty straightforward in terms of understanding it. In 1-D it works like this ... Do a Taylor series expansion to find [tex] x_{n+1} [/tex] given [tex] x_n [/tex] , where [tex]x_n = x(n \cdot \Delta t) [/tex] : [tex] x_{n+1} = x_n + v_n \cdot \Delta t + \frac{1}{2} a_n \cdot \Delta t^2 + \frac{1}{6}x'''_n \cdot \Delta t^3 +[/tex] ... Similarly, [tex] x_{n-1} = x_n - v_n \cdot \Delta t + \frac{1}{2} a_n \cdot \Delta t^2 - \frac{1}{6}x'''_n \cdot \Delta t^3 + [/tex] ... where [tex] v_n, a_n, x'''_n [/tex] are the velocity, acceleration, and 3rd derivitive of x, respectively, at time [tex] t= n \cdot \Delta t [/tex] Add these two equations: [tex] x_{n+1} + x_{n-1} = 2 \cdot x_n + a_n \cdot \Delta t^2 +[/tex] ... or [tex] x_{n+1} = 2 \cdot x_n - x_{n-1} + a_n \cdot \Delta t^2 + [/tex] ... Note the cancellation of the odd-order terms, so that the error is actually of order [tex]\Delta t^4[/tex], not [tex]\Delta t^3[/tex]. All you need to calculate [tex]x_{n+1}[/tex] are the previous 2 values of x, as well as the acceleration at time [tex]n \cdot \Delta t[/tex], which you calculate from the Forces and masses in the system. In 2-D you'd need to calculate the x- and y-components of the accelerations, then apply the algorithm to find [tex]x_{n+1}[/tex] and [tex]y_{n+1}[/tex] . There might be a common name for this algorithm, if anybody knows it feel free to post the info. |
| May3-08, 09:55 PM | #22 |
|
Mentor
Blog Entries: 10
|
p.s. I just looked over my code, and found that I used the algorithm I described in message #21. Somehow I thought I later changed this to Runge-Kutta but apparently not. I can't figure out, from a quick glance at the code, just what I'm doing to the force to make it "behave" at close range. I would have to find some 3-year-old handwritten notes that I have somewhere to figure that out again. |
| May4-08, 12:24 AM | #23 |
|
|
Anyone feel like sharing one of their simulators? Would be interesting.
|
| May4-08, 12:59 AM | #24 |
|
|
The guys at NASA, NSA, and whoever, should have devoted quit a few man-years at this. So they may have found a different method than interating t, and updating V_i and X_i. There's the Hamiltonian, if you've heard of it. It's an alternative, equivalent to Newtonian mechanics. What I'm trying to say, is that it may be possible to iterate values in some other mathematical space, rather than velocity and position. Angular momentum and Kinetic energy perhaps; I have no idea really. Just offinging possibilities.
|
| May4-08, 09:00 AM | #25 |
|
Mentor
|
|
| May4-08, 10:42 AM | #26 |
|
Mentor
|
There are many, many other orbital propagation techniques. One approach is to use Keplerian elements (e.g., [itex]a,e,i,\Omega,\omega,M[/itex]) rather than position and velocity. In the case of two bodies, all Keplerian elements but the mean anomaly are constant and the mean anomaly is a linear function of time. Propagation is easy and exact. Making sense out of the elements (e.g., plot positions on a computer screen) takes a little work, but not too much. Now consider a stellar system which comprises a single star and several planets. The planets' orbits can still be described in terms of Keplerian elements, but these now exhibit time-varying behavior. The variations are small, so perturbation techniques can be put into play. NASA used such an approach during the Apollo era, and still uses it in some arenas today. |
| May4-08, 10:40 PM | #27 |
|
|
An interesting possibility to avoid close-approach divergence for any pair of bodies, might be to switch to elliptical orbits + perturbations (for the pair only) based upon some nearness condition, then switch back. It may even be possible to survive a direct hit where the mass centers pass through one another. |
| May5-08, 10:58 PM | #28 |
|
|
In the above I failed to mention the possibility of close encounders of hyperbolic and parabolic trajectories where these might also be degenerate (head on collisions).
|
| May10-08, 11:04 PM | #29 |
|
|
I'm also trying to make an n-body orbital simulator, its going quite well - i've recently upgraded from euler to fourth order runga-kutta.
I've been using Cartesian coordinates for all of my work so far, and for the actual calculations i plan to continue - but i need to be able to use keplerian orbital elements instead of state vectors for initial conditions. I was wondering if anyone out there had experience or direction on how to convert between orbital elements and state vectors besides drowning myself in geometry. Thanks! |
| May15-08, 11:41 AM | #30 |
|
|
Regardless of what everyone is telling you, your method will work fine. Just be prepared to use very small time steps if you are using Euler's method.
Besides inaccuracies that can occur due to the approximate nature of the solution, the near-collision "explosion" can be solved by simply defining the force piecewise. Calculate the distance between each pair of bodies (this must be done anyway) and see if it's less than some minimum value (this can be as simple or as complicated as you like). Then decide whether or not you want to "do" the force there, and act accordingly. Otherwise, you could use a similar method to use conservation of momentum to have them collide (elastically or inelastically) like billiard balls. Or have them lump together and run until all masses have lumped together. There's a lot of potential for fun and good programming in what you're talking about.Good graphics can be done in Java, C, C++, C#, Visual Basic, etc. For 3-D, you may even look into DirectX or OpenGL. The programming won't be hard, but there are some things you can do to make it easy on yourself. Look for libraries with functions / objects you can use. I recommend taking the opportunity to explore OO approaches, if you're not already familiar with these. You can make objects for vectors and massy particles and this will greatly ease the notation. Have fun with it. |
| May17-08, 08:50 AM | #31 |
|
|
May I ask, for a given accuracy of 10^-5 say, and for a given orbit lasting 1 year, which integration method is the fastest?
|
| May17-08, 09:43 AM | #32 |
|
|
I would suspect that you can't do much better than the fourth order adaptive stepsize Runge Kutta algorithm.
|
| May17-08, 11:33 AM | #33 |
|
|
Does that mean repeating with a smaller time interval until all 3 steps of 4th order Runge-Kutta agree within an error margin?
|
| May17-08, 12:51 PM | #34 |
|
|
I'm not sure precisely what happens, but I'm pretty sure that a timestep is taken with one RK method and then another is taken with one which is of one higher order, and if the difference is within the error bars, it goes with it. Otherwise, it tells you what the timestep should be to get your accuracy. It has the benefit of remaining as accurate as you tell it (within reason) and not being *too* when the forces are negligibly small (for instance, why use a timestep of h = 1.0e-10 both when the force is large and changing quickly AND when the force is next to nothing and staying put?)
|
| Thread Closed |
| Thread Tools | |
Similar Threads for: Create an Orbital Simulator
|
||||
| Thread | Forum | Replies | ||
| Programming an Orbital Simulator | Programming & Comp Sci | 16 | ||
| Is it possible to create Orbital construction yards for Spaceships? | General Astronomy | 6 | ||
| Looking for old DOS orbit simulator. | General Discussion | 4 | ||
| Orbital simulator and non fixed orbit | Introductory Physics Homework | 1 | ||
| Simulator | Aerospace Engineering | 2 | ||