TheHappyKoala / Harmony-of-the-Spheres

Newtonian n-body gravity simulator
116 stars 19 forks source link

Calculate future positions of masses using orbital elements #115

Closed TheHappyKoala closed 4 years ago

TheHappyKoala commented 4 years ago

Happy almost Monday 😄 !

I remember you'd written some code for the Lambert solver that would stop it from calculating a trajectory that would pass through the planet the spacecraft is departing from, since, generally speaking, such trajectories do not make for healthy spacecraft 😅.

I'm asking because chances are I've consigned that code to the dust bin of history with some of the changes that I made to the solver last summer. Alternatively, that check is only done with respect to the planet whose sphere of influence the spacecraft is in, the issue being that when travelling from Earth to, say, Mars, the trajectory is actually calculated with respect to the Sun (yields much more accurate results, but when calculating a trajectory to the Moon, you do so with respect to Earth, still).

Not sure I'm making much sense here, but if there's a chance you remember anything related to the above, lemme know 😄 . Aint a big issue but I've probably lost 120 crews today alone 😭

HugoGranstrom commented 4 years ago

I'm afraid I never wrote any code that did that sadly 😅 I may have said that we would eventually need it (which we do obviously 😂) but no code was ever written. My reasoning was along the lines of that the nearest distance to the starting body (perihelion) of the orbit must be greater than the starting body's radius. But I never came any longer with that idea 😅

HugoGranstrom commented 4 years ago

So if we want to calculate the velocities with respect to the Sun but we start from the Earth, then we could get into this problem. My main concern is how we calculate the shortest distance to the starting body if the orbit is hyperbolic with respect to it

HugoGranstrom commented 4 years ago

I'm not sure how we would solve it if we does find a way either 😅 I think we have one variable to play with (how many revolutions around the sun before we arrive)

TheHappyKoala commented 4 years ago

Hahahaha, ah, got ya!

The risk of this happening is only high enough to be bothered about when you are in a really tight orbit around the planet, so what we could implement is a simple brute force check, and if that check determines that there will be collision, you simply display a validation message to the user telling them that they have to try a trajectory with a different tof or depart from a different point in the orbit.

HugoGranstrom commented 4 years ago

Found a formula we perhaps could use here: https://en.m.wikipedia.org/wiki/Hyperbolic_trajectory#Impact_parameter_and_the_distance_of_closest_approach

HugoGranstrom commented 4 years ago

Yeah that seems like a sane way to handle it 😄👍😊 The user should be the one to handle it for us 😂

TheHappyKoala commented 4 years ago
Screen Shot 2020-02-02 at 18 04 18

The formula is probably the way to go, but I'll deal with that once the orbital insertion controls are done and dusted... Don't want to get distracted - happens very easily to me, I have the attention span of a 🐶!

On the subject of getting distracted... Look, our first procedurally generated planet! Nothing fancy, but soon enough their appearance will be determined by their temperature, mass and so on... Cool times ahead 😄

Have a mighty good start to February... Almost spring now 🌞 !

TheHappyKoala commented 4 years ago
Screen Shot 2020-02-02 at 18 15 01

The white are ocean basis / lava plains... Clearly I'm yet to figure out how to work with colors 🤣

TheHappyKoala commented 4 years ago

And we need procedural gas giants, neptunes and what not!

TheHappyKoala commented 4 years ago
Screen Shot 2020-02-03 at 21 22 17

Man, this is so cool I'm shitting ma pants!

HugoGranstrom commented 4 years ago

😮😮😮😮😮😮😮😮🤩🤩🤩🤩🤩🤩🤩🤩🤩🤩🤩🤩 THAT'S BLOODY BRILLIANT!!! 🌎🌍🌏🚀🚀🚀🚀🚀🚀 It looks so good! Is there algorithms for doing this or what's going on?

TheHappyKoala commented 4 years ago

It's gonna take the exoplanet scenarios to a whole other level :D But yes, there are! I'm using something called perlin noise subject to the constraints I've already mentioned; temperature, mass and so on.

Gonna make a big commit this weekend... If you like algorithms I think you'll enjoy reading through the code 😄

HugoGranstrom commented 4 years ago

Yes it really will take it to a new level 🚀😉👍

Gonna check it out, and YES you can bet I'm going to enjoy reading it 😁

Haven't really started with the Orbital Elements yet 😅 I've been prioritizing working through the exercises in my programming course, but now the next one is due at the end of February so I'll do my best not to procastinate i anymore 😅😂

TheHappyKoala commented 4 years ago

No rush! I work at a very slow pace, too. And I just realised I'm shit posting in your issue... Sorry 😇

HugoGranstrom commented 4 years ago

Nah, this is how we roll 😎 we post our shit wherever we like 😉

HugoGranstrom commented 4 years ago

Finally the puzzle pieces in my head has fallen into place! 🤣 I have found formulas for converting to and from orbital elements here and here. And on Wikipedia I found how to propagate them forward in time. So now it's just a matter of implementing them.

I'm thinking of creating a TS type called OrbitalElements so we don't have to specify all of them as inputs to our functions. What do you think about that? 😄

HugoGranstrom commented 4 years ago

Is there anything from your branches that could cause any headache-inducing merge conflicts or am I free to do whatever I want in lambert.ts? 😅

TheHappyKoala commented 4 years ago

Go for it, and yay 😄 !!! That will make the space flight stuff so much more interesting since you won't have to wait for the trajectory cruncher to generate the future position of a mass. Maybe we could add a date control, too, so that people could view the solar system at different points in time???

TheHappyKoala commented 4 years ago

And I really need to merge the gatsby branch soon... It's turning into a monster, haha

HugoGranstrom commented 4 years ago

Haha yeah it takes quite some time right now 😅🤣 The date control should work, but I don't know how accurate it would be for longer timescales 😅 My Earth is already off by 0.02 AU after one year. Don't know how the numbers look for our integrators but they might be off by the same 🤣 It would be a neat feature nonetheless 😉 It wouldn't be to hard to do once we can do it for one mass

HugoGranstrom commented 4 years ago

We have our monster of our own we could use to tame Gatsby: RKN12 🤣 🤣

TheHappyKoala commented 4 years ago

I should have left it at implementing Gatsby but instead I doubled down on the gitigans by baking other features like new textures, procedural stars etc into it... Will I ever learn 👽 ?

Yea, the farther into the future, or past for that matter, you try to ascertain the position of a planet, the less accurate it will be, especially for comets that are often perturbed by Jupiter. Would be kind of cool to create one scenario where you have a set of clones running on orbital elements and compare their positions to a set of planets whose positions are determined by an integrator and get a sense of how important perturbations are to our solar system.

Yes, we should wire reality up to RKN12 and make things happen 🤣 .

HugoGranstrom commented 4 years ago

Gitigans have a certain charm to them 😂 it's hard to resist sometimes. You have gotten loads of work done nonetheless 😉

Oh yeah, that would be super cool 🚀🚀😄😄😄😎 I think we would pretty quickly see the effects for certain bodies (mercury) and some would probably not change much (Neptune)

HugoGranstrom commented 4 years ago

Do you prefer to have the Orbital Elements in degrees or radians? For doing all the future telling it's more convenient to have them in radians all along. Do you have any opinions on the matter? 😄

TheHappyKoala commented 4 years ago

Nah, doesn't really matter. For whatever reason I have a natural preference for degrees (guess they feel more familliar!), but at the end of the day converting between the two is a piece of cake. Fact of the matter is that switching to radians might make more sense seeing as THREE.js uses radians and not degrees 🚀 !

TheHappyKoala commented 4 years ago

First commit for the procedural planets is on its way... Just the terrestial ones, but they are trickier to generate than the gas giants, so there's still a yay factor to this commit, I'd say 🤣

HugoGranstrom commented 4 years ago

Radians it is then! 😉 Felt better getting your opinion on this so I didn't suddenly change it to radians and all your code assuming degrees stopped working 🤣

Awesome! 🚀 Looking forward to populating a whole galaxy with procedural planets 🤣

HugoGranstrom commented 4 years ago

I have btw managed to get the stateToKepler, keplerToState and propagateOrbitalElements to work so now I just have to make functions for traversing a SOITree and doing all the propagation for all bodies.

I'm thinking of making two different functions:

Not sure how to handle the particles though... 🤔

Does these sound like reasonable cases? Or do you have other cases you would want implemented as well? 😄

TheHappyKoala commented 4 years ago

Ohhhh... Let me get back to you tomorrow with some feedback regarding the points you brought up... Right now I'm obsessively trying to wrap up the procedural planets... So close but there's this little issue pertaining to the interpolation of colors that is driving me nuuuuuuts 🤣

HugoGranstrom commented 4 years ago

No hurry 😉👍

Oh that is so annoying when there's just one small thing left and it's not cooperating 😔😦🦕

TheHappyKoala commented 4 years ago
Screen Shot 2020-02-14 at 19 07 23

LOL. Search terms that brought people to our website from google... One of those guys must have been VERY disappointed when he saw what our site was actually about 🤣 . I mean, wtf! Should I laugh or loose faith in humanity?

HugoGranstrom commented 4 years ago

Hahahahaha, what the #$_* 🤣🤣🤣🤣🤣🤣🤣🤣🤣🤣 An idea for the future perhaps?

TheHappyKoala commented 4 years ago

X-Rated HOS... 🤣 No, somebody will have to fork HOS and create it themselves

TheHappyKoala commented 4 years ago

I would love it if HOS was the basis of the world's first, ehrm, 3D space sex simulator

HugoGranstrom commented 4 years ago

🤣🤣 I would be hugely impressed if someone managed that feat

TheHappyKoala commented 4 years ago

Totally. How you doing? Any extravagant plans for the weekend?

HugoGranstrom commented 4 years ago

I'm doing fine, school is really chill right now and life is rolling on 😄 the weather does seem too nice in the weekend so hopefully I will get some coding done. How are you and what's your plan? 😊

TheHappyKoala commented 4 years ago

I'm doing pretty good. Work's still very challening and a lot of fun, and on my way home today I bought two beers at bolaget, so tonight I'm gonna drink beer and work on the procedural planets 🤣 I'm such a bad boy.

HugoGranstrom commented 4 years ago

Sounds great!😄👍 Haha maybe a more "open" mind can be helpful there 😅🤣

TheHappyKoala commented 4 years ago

Screen Shot 2020-02-15 at 21 03 10

TheHappyKoala commented 4 years ago

Creating world's is so much fun!!! This is a cool pic because it is the first time I have generated a planet based on its temperature, mass and radius

HugoGranstrom commented 4 years ago

Wow! 😮🤩🤩🤩 That looks so realistic but still a bit random 😉 what's thr difference between green and brown?

TheHappyKoala commented 4 years ago

Brown is supposed to represent mountains... I need a more realistic model for how vegetation changes with elevation. Habitable planets are tricky... World's like Mars and Mercury are more gratifying 🤣. Also, I need to take the longitude of a pixel into account, so that poles are covered by ice caps, whereas somewhat above and below the equator you get desserts.

HugoGranstrom commented 4 years ago

Ahhh I get it 😄👍 Sounds like a lot of work 😅

TheHappyKoala commented 4 years ago

Hms, no idea why I hadn't thought of this before, but by passing a uniform to the shader and calculating the temperature (black body, taking greenhouse gases into account is beyond ma paygrade) of Earth based on its distance from the Sun, I can change the look of Earth... So take it out into the asteroid belt and it freezes over, and inwards towards Mercury and it becomes a dessert world. That'll have to wait for later, though... Need to make small and manageable commits 😅

TheHappyKoala commented 4 years ago

OMG, OMG, OMG!!!

You know how to make sure that some property on an object is not undefined or null, you have to do a check like this:

data !== null && data.person && data.person.name && doSomething(data.person.name);

Well... With the newest version of JavaScript, you can do the same check like so:

data?.person?.name? doSomething(data.person.name);

🎈 💯 🏅 🎉

HugoGranstrom commented 4 years ago

Wow, that's such a brilliant idea in its simplicity 😉😊😎 Seeing how Earth changes depending on the distance to the Sun

Didn't actually know you had to go through all that trouble tbh 🤣😂🤣😂 but the new way is much neater and shorter, guess it saves you a lot of time?😊

TheHappyKoala commented 4 years ago

Doesn't save you that much time, it's more the experience of reading code that improves... It's the difference between caligraphy and writing like this "hOw u dUiN?!!" with bright red marker 🤣

TheHappyKoala commented 4 years ago
Screen Shot 2020-02-17 at 21 07 46

Maaannn.... So close now, even figured out how to make procedural gas giants!!! Gonna tweak the model that determines the type of planet based on its characteristics, and then I'm gonna put these guys to the side and merge this branch, and make HOS great again 🤣