7

SP4CEBAR 2021-05-21 16:50 (Edited)

This program simulates gravitational forces, and the acceleration, velocity, and position of a satellite. If you're interested, I put comments in the code to explain how it works.

V0.1 Bug fixed, the orbit is now much more realistic

V0.2 Added a trail (I tried making a path to show your current orbit (in advance))

V0.3 ADDED PATHS with a dynamic resolution, this was an awful lot of work

V0.4 small optimization: the path doesn't have to be drawn all the time (recursive path drawing is slow)

V0.5 added the moon V0.5.1 small bug fix

V0.6 added gravity to the moon

was8bit 2021-05-24 04:22

Itâ€™s rather fun trying to adjust things just right to create a new stable orbit :)

was8bit 2021-05-24 16:05

Ooooo, that's very cool :D

SP4CEBAR 2021-05-24 19:56

Thanks

CubicleHead 2021-05-25 11:51

I like the new goal

was8bit 2021-05-25 15:50

I like the moon :)

nathanielbabiak 2021-06-29 02:41

I like this - it's the essence of Kerbal Space Program! Do you have any plans to add patched conics to allow orbit around the moon? (Or, I might do it myself if I find the time...)

nathanielbabiak 2021-06-29 02:59 (Edited)

I started studying aerospace engineering in 2014 or 2015. I was playing KSP with a mod installed called Kerbal Engineer. It's basically a mod that provides an astrodynamic flight computer. KSP had an update around that time, and it broke every single mod for the system for months, and I was so dependent on Kerbal Engineer that I manually re-created the entirety of it in Excel from this source.

(At the time, I had thought that learning astrodynamics would help me pass my boards... It did not.)

So, what I'm getting at is... I'm going to pull an all-nighter and make moon orbit possible. This is fun!

was8bit 2021-06-29 03:17

:)

nathanielbabiak 2021-06-29 07:26 (Edited)

I uploaded here.

This is harder than I thought... I'm running into a few issues and some features still aren't done. It's just too much for a one-night session - I'll try a bit more later this week though!

SP4CEBAR 2021-06-29 09:00 (Edited)

Thanks, I didn't think about giving the moon a gravitational force, but it shouldn't be that hard to do, I might add that at some point (edit: I just did)

my plan for this simulator is to make a space game, where you can build a rocket, fly it, earn money from funding, upgrade the rocket, repeat. And do missions in orbit around the earth, on the moon, on mars, on titan, and in outer space

SP4CEBAR 2021-06-29 10:34 (Edited)

While adding it I came across a very weird bug:

TRACE FGX

FGY=RY*FG/R

TRACE FGX

These two trace commands return a different value of FGX when the subprogram they belong to is called by a certain other sub

I'll post the program here just in case this rare bug is caused by NX (edit: it isn't)

SP4CEBAR 2021-06-29 10:40 (Edited)

I found it :)

CALL GFORCE(X1,Y1,XE,YE,CE,RX1,RY1,R,**FX,FX**)

Instead of FX,FX it should be FX,FY

SP4CEBAR 2021-06-29 10:51 (Edited)

In this version you can't really get a stable orbit around the moon, because the gravitational forces from the earth are bigger

SP4CEBAR 2021-06-29 10:52 (Edited)

I think my scale is wrong, the earth is way to strong compared to it's distance to the moon, but this scale can easily be changed by changing the GRAVITY variable

nathanielbabiak 2021-06-29 18:48 (Edited)

You can't get a stable orbit around the moon because of the three-body problem.

The only way to fix this is to allow scale changes that match the order-of-magnitude of the actual solution to that problem. That is to say, you need to be really close to the moon - so close it'd look like you hit its pixels - and to avoid that look you'd need to make the game zoom-in.

SP4CEBAR 2021-07-01 20:00 (Edited)

Quote:

and to avoid that look you'd need to make the game zoom-in.

Thanks, That makes a lot of sense

nathanielbabiak 2021-07-02 09:20

Did you implement Kelper's laws to model the orbits?

When I did this in Excel years ago, I was able to just do it with free body diagrams! It seems Excel calc's with double-precision, but LowRes NX only calc's with single-precision, so the accuracy (and speed) just isn't sufficient to iterate through too many orbits.

So is that was the recursion comment is about in your code?

nathanielbabiak 2021-07-02 10:19 (Edited)

I'm asking because this is horrible!

Edit: seems like the fixed-point iteration will work just fine.

So now I'm really stumped - what's the recursion for in your code?

SP4CEBAR 2021-07-04 07:38 (Edited)

My program has recursion because I've made a model of physics

In my program, I'm first calculating the relative distance from the satellite and the planet (dx and dy), I can use these to calculate "r" (pythagoras)

using the formula: Gravitational_Force=G*M*m/r I can calculate the gravitational force

This force is pointed straight towards the center of the earth, so I found a way to decompose that force using uniformity with dx and dy and r (FGX=RX*FG/R FGY=RY*FG/R)

To calculate the nett-force I only have to add the vector of thrust (user input) to this gravitational force

With the nett-force I can calculate the acceleration (ax=fx/m ay=fy/m)

With the acceleration I can modify the velocity (add vx,ax*dt . . . . . add vy,ay*dt)

With the velocity I can modify the position (add x,vx*dt . . . . . add y,vy*dt)

SP4CEBAR 2021-07-04 07:46

So with kelpers laws you can calculate an explicit formula for the orbit?

SP4CEBAR 2021-07-04 07:51 (Edited)

Quote

I'm asking because this is horrible!

To make a path I attempted to calculate an explicit formula for my model of physics, that was also quite horrible: I had to turn these monstrosities of a formula into explicit formulas

```
X=N*(N*(FTX+GRAVITY*(C/((XE-X)^2+(YE-Y)^2)/SQR((XE-X)^2+(YE-Y)^2))*XE-X)/M*DT+3)*DT
Y=N*(N*(FTY+GRAVITY*(C/((XE-X)^2+(YE-Y)^2)/SQR((XE-X)^2+(YE-Y)^2))*YE-Y)/M*DT-3)*DT
```

SP4CEBAR 2021-07-04 07:53 (Edited)

When I realized that the results would be limited, it would need to be more and more complicated if I want to add more stars, planets, or moons, I decided to just go for the slow approach to just calculate the recursive formula in advance every time

nathanielbabiak 2021-07-08 23:40

I agree 100% - it's super hard, but I really don't like the "wobble" of the orbit due to rounding issues either... I've actually been focused lately on an astrodynamic approach. I'll have an upload in a few weeks.

SP4CEBAR 2021-07-15 19:18

Ah the wobble, that's quite annoying, the path will get outdated because the orbit changes without any user input

SP4CEBAR 2021-10-25 15:45 (Edited)

@nathanielbabiak I just made a new simulator which has the entire solar system, and it has zoom

nathanielbabiak 2021-10-25 23:49 (Edited)

I saw that one - it's very nice!

(I'm embarrassed... I kind'a gave up on mine a while back. I finished the orbital dynamics two-body solver, but it needs double- or quad- precision to work at solar system scales, and NX only has single-precision. Implementing a double-double-precision math library seemed like too much work!)

was8bit 2021-10-26 03:57 (Edited)

Always remember this is for fun :) when something is no longer fun, find something that is fun :)

SP4CEBAR 2021-10-26 08:54

@nathanielbabiak Thanks!

Feel free to use my solar system to test your orbital dynamics

Also, maybe you could use NX's RAM to store large variables

Log in to reply.