Work in Progress

Space Explorer


SP4CEBAR 2021-10-25 14:52 (Edited)

Orbit trough our solar system with a moon-shaped spacecraft


This program is a follow up on my planetarium

Space Explorer.nx | Open in app
2021-10-25 17:23
Space Explorer.nx | Open in app
2021-10-25 15:11
Space Explorer.nx | Open in app
2021-10-25 15:10
Space Explorer.nx | Open in app
2021-10-25 14:52

SP4CEBAR 2021-10-25 14:54 (Edited)

I guess I didn't wait for the end of my exam week to get started with this...

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

the scale of the coordinates is soo much larger here than in my previous simulator

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

Now I've just got to find a way to get a stable orbit around planets or moons...

EDIT: That's gonna be impossible when the spacecraft goes around the sun in the wrong direction...

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

I better continue preparing exams...

SP4CEBAR 2021-10-25 17:24

I scaled the power to the zoom value, so zooming in makes your thrusts more precise

SP4CEBAR 2021-10-25 17:28

It's really hard to get an orbit around one of the planets
the planet coordinates are generated using sine and cosine, while the spacecraft is powered by a model of physics, so I think I'd have to make the two compatible before I can put the spacecraft in orbit around earth

SP4CEBAR 2021-10-25 17:30 (Edited)

If anyone can pilot the spacecraft to a stable orbit around a planet, please let me know
I think Jupiter would be the best planet to try

nathanielbabiak 2021-10-26 00:00 (Edited)

As programmed, there's no stable orbits for the spacecraft. In the two-dimensional simplification of astrodynamics, stable orbits will only be possible within the sphere of influence (SOI) of a celestial body.

You can use the formula at SOI (in terms of SMA, m, and M), but you'll need the semi-major axis (SMA) of the orbit.

Next, you can use the formula at SMA (in terms of \mu and \epsilon), but you'll need the specific energy (\epsilon) of the orbit.

Lastly, you can use the formula at \epsilon (in terms of v, \mu, and r).

SP4CEBAR 2021-10-26 17:10

That sounds really complicated, I'll look into it
But for now I think I'll give earth more gravity and the sun less gravity
So that I can tweak the parameters to get the two systems more in harmony (same velocities) and so that I can find a position and velocity at which the spacecraft can spawn in orbit around earth

SP4CEBAR 2022-03-27 21:44 (Edited)

I just injected the rotation matrix into the cone section formula
now I can make orbits from a formula

SP4CEBAR 2022-03-28 11:16

I could switch the orbit line indicating sprites between two locations, so that I can get a denser line with half the brightness (which doesn't really matter for an indicator line)

Or I could use rasters to place two dot sprites at the right locations each raster, to form the right cone section

SP4CEBAR 2022-03-28 11:30 (Edited)

Now I've got to find a way to plot that formula (A*X^2 + B*Y^2 + C*X + D*Y + E = 0)
It's kind of tricky, I'd love this to be a parametric formula, but it doesn't seem to be able to be converted to one, I could turn it into the Y=... format, but that'll give me a nasty formula

So, I think the only thing left is to fill X into it, then it'd give us F= A*X^2 + C*X + E, and we're left with the equation B*Y^2 + D*Y + F = 0, which we can solve with DI= B^2 - 4*D*F and then
IF DI>=0 then
Y1= (-D -SQR(DI))/2*B
Y2= (-D +SQR(DI))/2*B

It's for sure gonna take a bit more calculations per point to plot this

SP4CEBAR 2022-03-28 11:31

An then I've also got to take the rotation matrix into account

nathanielbabiak 2022-03-28 14:30 (Edited)

The math exercise you are describing was pretty much the life's work of the folks who published, resulting in the Wikipedia articles I've hyperlinked above. It's crazy math ("trigonometry on steroids"), and there's no shortcuts that keep the astrodynamic system consistent with itself (not even realistic, just consistent with itself).

It's kinda like the metaphor: "climbing a tree won't get you to the moon, but you'll make a lot of progress more quickly than building a rocket." (You might not need to go to the moon to achieve your goals, and building a rocket is a huge effort...)

(I scraped my LowRes astrodynamic modeler since it wouldn't allow sub-meter surface accuracy, but it's entirely feasible if you don't land on bodies.)

SP4CEBAR 2022-03-28 15:14 (Edited)

I noticed that the game "Spaceflight Simulator" only shows orbits around one gravity source at a time, and it works because it's only orbiting one mass at a time, as soon as you leave or enter the gravitational influence of one mass it can take that mass as the new gravity source

nathanielbabiak 2022-03-28 18:12 (Edited)

That single-orbit simplification is called a patched conic approximation. It works pretty well - even real-world spacefaring nations use it to model short-term orbits (less than a few months). But, the crazy math I mentioned is required to determine the "boundary conditions" where the spacecraft would swap between being modeled in one celestial body's gravity well vs. another celestial body's.

If the spacecraft remains (for a long time) at the boundary region, patched conics aren't accurate.

SP4CEBAR 2022-03-28 18:46

Wow, I'm glad I don't have to make an accurate simulator

Also, is a lagrange point such a boundary region?

nathanielbabiak 2022-03-28 19:28 (Edited)

Yes, the restricted three-body problem yields the five Lagrange points (but no other "boundary condition" effects besides various orbits around those points).

Hey I totally misunderstood! You're not making a 2-body solver. Ugh! My mistake. Avoid this math like the plague! Definately use rotated elliptical paths rather than this crap. Sorry - didn't mean to go off topic.

As far as your recent post goes, the formula for parametric rotated ellipsis is fully defined - try an internet search for parametric rotated 2D ellipse.

SP4CEBAR 2022-03-28 22:43 (Edited)

Thanks for all the replies and feedback, I found the complicated orbit math quite interesting, as hard as it looks, I'm somehow able to understand it

I can do a parametric ellipse, but that wouldn't allow me to use parabolas and hyperboles, which are also possible paths for an orbiter
But because it's so much simpler, I could just use it for now

SP4CEBAR 2022-04-06 20:06 (Edited)

I just added my cone section plotter

SP4CEBAR 2022-04-06 20:08 (Edited)

Now I just got to figure out what parameters make the right orbit

SP4CEBAR 2022-04-12 20:51 (Edited)

@nathanielbabiak so I've done a little bit of research, to get the right parameters for my rotation matrixed "P1*X^2 + P2*Y^2 + P3*X*Y + P4*X + P5*Y + P6 = 0" cone section (I can already plot this base formula), I think I need to set the apoapsis and the periapsis of the orbit, and use that to calculate the Orbital eccentricity and then... I don't know, can I just use the Orbital eccentricity as my parameter P1? (In the current version of this program P1 is used to scroll through the cone section types with the left joystick), and do I need to calculate more orbital properties than just the eccentricity? (I can wait with adding orbital speed until the path plotter is working)

SP4CEBAR 2022-04-12 21:39 (Edited)

I'm pretty sure this is going to be very useful
But then I'd still only be able to calculate the ratio of P1 to P2 to P3 from the eccentricity

nathanielbabiak 2022-04-13 03:03 (Edited)

It seems you want to use an existing body of knowledge (consisting of commonly studied expressions or mathematical terms/definitions) and mathematically develop some end resultant, right? You want to get to an X-Y system for representing orbits mathematically... The body of knowledge you're looking for is called astrodynamics or orbital dynamics. Unfortunately, there's no avoiding it, no shortcuts. (I'm not saying you absolutely must learn it "all" - or even learn it "well"!)

Read through this to get an orientation to the terms and math that's required. There's a bunch of other Wikipedia pages I could link in addition, but that's the essential one.

Robert Braeunig's website homepage shows "This Web page can trace its roots to the author's project to write a computer program simulating the launch of a rocket to orbit." Read through his webpage Basics of Spaceflight. This will yield the information you seek. (The rest of his website may be skipped, it covers orbital mechanics rather than dynamics.)

MIT also offers a 100% free online course. It's here. It's described as graduate level, perhaps that validates the hard work involved, or perhaps it's daunting. (Your pick!)

If you've got a mathematics (or possibly pure or theoretical physics) degree, (engineering won't cut it), then it's feasible to read through either source in maybe a week, just to get your bearings, and then investigate deeply from there.

nathanielbabiak 2022-04-13 03:26 (Edited)

Not sure if you've seen it, but there's a game that was pretty popular a few years back. I played from 2015 to 2020. (I still have my solar system save file!) The developers were friendly with their modding community (making the game pretty easy to modify). One mod in particular, MechJeb, calculated a bunch of astrodynamic data, it made things a tiny bit easier. But, in mid-2016 the mods (including MechJeb) broke due to incompatibility with the the version 1.1 update.

So I built my own astrodynamic calculator... in Microsoft Excel. (I'm not proud of Excel being the basis, but I don't have any professional programming experience, and finding a Windows IDE seemed like a pain.) I used both of those sources and it took me a few months. And, just as I finished the mod authors updated MechJeb, and I didn't need my version anymore.

My point in this rambling story is I learned something back then that may be helpful. Excel stores numbers as a modified version of FP64, LowRes NX uses FP32. Excel has 15 digits of guaranteed accuracy (enough for an orbital simulator) but LowRes NX only has six.

You might want to be careful about how much accuracy you need. After all, the numbers you'd be working with are astronomical - hehe, pun intended!

(Off topic: Lately I've been working on using those six guaranteed digits to their limits on an orbital simulator of my own - I'll have an upload soon.)

nathanielbabiak 2022-04-13 03:47 (Edited)

Sorry for the two wall-o-text posts. I just keep feeling bad because you're asking precise questions, but you don't know the terms to Google search for. Was just trying to teach you to fish rather than giving you a fish.

The answer to your specific question is here, although that whole page has a bunch of good info.

SP4CEBAR 2022-04-13 07:41 (Edited)

Thank you so much for all the effort! This will definitely be enough to get me going

[quote] "If you've got a mathematics (or possibly pure or theoretical physics) degree, (engineering won't cut it), then it's feasible to read through either source in maybe a week, just to get your bearings, and then investigate deeply from there."

I've got a pre-university degree with physics, math-B (essential calculus), and math-D (more in-depth calculus) so I've been introduced to the basics of most fields of mathematics

SP4CEBAR 2023-02-04 10:54

It's probably possible to make it 3D in NX, the curve already has a rotation matrix built in so maybe I can put a more complicated matrix in there

Log in to reply.