#Distance between two celestial bodes.

109 messages · Page 1 of 1 (latest)

rose pilot
#

Two celestial bodies exist in a 3-dimensional (x,y,z) universe where only newtonian mechanics apply.
Write a function which calculates the distance between these two boddies at any time, given their initial positions and velocities.

struct body
{
    array<double,3> position; // (x,y,z)
    array<double,3> velocity; // (dx,dy,dz)
    double mass;
};
double distance(double time, body const& initial_a, body const& initial_b);

Hint: this is the two-body problem, which is well understood. Use any resources you like 😉

EDIT: The solution to the algorithm can be seen in my latest post. I've left the implementation as an easier challenge. <#1021424011835613244 message>

supple current
#

I think me participating would be unfair (I worked on just that for KSP)

#

(and I've been playing with such, off and on, since I was 15)

fleet hatch
#

I wonder if drag even exists

supple current
#

it does, but it's microscopic

#

especially compared to the mass of a CB

fleet hatch
#

yeah but with this challenge it is just:
abs(a_position - b_position) - ((a_velocity - invert(b_velocity)) * time);
Since gravity/drag isn't defined.
Though even that answer isn't 100% correct, but it would be as simple as that.

rose pilot
#

you can assume drag is either negligable or non-existent XD

#

also, awesome you've worked on KSP

#

easily my favourite single-player gaame

fleet hatch
supple current
#

the solution is to numerically integrate the position over time

#

this challenge involves knowing newton's laws of motion and the force acting on a body due to gravity, applying that to 3d vectors, and numerically integrating

ornate copper
#

How about systems like Pluto-Kharon in which the mass difference is not that big?

supple current
#

actually doesn't matter

#

what will happen is both bodies will move around

#

just doing it naively gets it right

#

(ie, when calculating acceleration of body A, assume B is fixed, and the other way)

supple current
#

do note that the usual integration method used in games is woefully inadequate (because it's wrong even for constant accelerations)

#

but it's good enough for seeing things work at all

ornate copper
#

Good to know, I'll investigate this when I'll possibly later in the future write some game with space flight simulation as well 🙂

supple current
#

using jerk (da/dt) is pretty good if applied correctly

#

position will be a 3-term (v, a, j) taylor series and velocity 2-term (a, j)

#

it's possible to calculate j analytically, but easier to do so numerically

worn solar
# fleet hatch I wonder if drag even exists

There will be some slight drag due to the celestial bodies being large enough that there will be a difference in gravitational strength between the closest point and furthest point.

#

But there's no radius information in the Body struct so, who knows how much that drag would be...

fleet hatch
#

(yeah but in this case its undefined)

fleet hatch
#

This challenge expects other people to know hidden variables.

sour scaffold
#

Exactly, I was about to say that

#

There are many parameters missing from the problem definition

supple current
#

not really

#

there are only 6 paramters: two masses, two initial positions, two initial velocities

worn solar
#

Could be seen as just a linear interpolation question

supple current
#

not with "newtonian mechanics" and "two-body system"

worn solar
#

newtonian mechanics apply
But considering this was said, you kinda have to rely on newtonian mechanics, I.e. G(m1*m2)/r^2 for gravitational force towards the other object.
And because F=ma, you just have to get the acceleration which is added to the velocity I.e. v = v_0 + (p_b - p)(G(m * m_b)/r^2)/m * t.
Then adding the velocity to the position p = p_0 + v_0 * t + v/2 * t * t, substituting v p = p_0 + v_0 * t + (v_0 + (p_b - p)(G(m * m_b)/r^2)/m)/2 * t * t, and then you just have to figure out a function that gives you p for whatever t is, after evaluating both bodies

fleet hatch
# supple current not with "newtonian mechanics" and "two-body system"

this kinda of expectation has to be set. Which was not done.
This can be easily seen as a "Beginner challenge".
Yes you said words, but the example code provided to set the variables more likely indicates the beginner challenge then the advanced one.

for these kind of things, links to resources would have been nice because then at least people know: OH he means the advanced challenge not the beginner challenge.

rose pilot
rose pilot
#

I think I overestimated the difficulty of this challenge. Hopefully, writing the function will be easier now the equation of motion, and the method to solve it, is given.

supple current
#

rotating reference frame?

rose pilot
supple current
#

oh, nm, I see where I went wrong

#

that's net acceleration of the body, not just gravitational

#

(haven't had coffee yet)

rose pilot
#

net outward acceleration is centrifugal acceleration minus gravitational acceleration.

supple current
#

yeah

#

I'm just not used to seeing it written quite like that

rose pilot
#

I had thought it was algebraically solvable, but I was wrong about that.

supple current
#

which?

rose pilot
#

the two body equation of motion

supple current
#

it is

rose pilot
#

you sure?

supple current
#

hold one, I've got some notes 🙂

rose pilot
#

yay tuxyay

supple current
#

sorry about the rotation

#

but doing that final integration will get you Kepler's law (3rd?)

#

this is why I didn't think participating would be fair. Those notes are a good 8 years old, I've known the steps for about 37 years

#

but that's why I got confused about your angular momentum term (h in my notes)

rose pilot
#

Ah, I think keplers law is a special case where the two bodies are in a stable orbit.

#

I will have to look into this more. Thanks 🙂

supple current
#

two bodies will be

#

(assuming they're points and thus tidal forces don't enter)

#

unless you mean "closed" instead of "stable"

rose pilot
#

I probably mean "closed".

supple current
#

however, the integral works equally well for both open trajectories

rose pilot
#

I mean if they're in an elliptical orbit, meaning they're always below escape velocity.

#

but if that integral works for both, that is very cool

supple current
#

the trick is 1) understanding that a in cosh(a) is area (2x) swept by the radius on a unit right hyperbola

#
  1. a in cos(a) is also area, not angle
#

(it's just the area (2x) swept by the radius on a unit circle going through that angle)

#

that's why orbital mechanics uses "anomaly" rather than "angle"

#

(I think:)

rose pilot
#

also, I think keplers law requires one of the bodies to be stationary (or near enough) at one of the foci of the ellipse

supple current
#

no

#

it's the relative position

rose pilot
#

very cool then 🙂

supple current
#

what happens is both bodies will have their own orbits around the barycenter and those orbits will have different (but compatible) parameters

rose pilot
#

In which case, you can calculate the angle at some time in the future by a path integral, and then the distance from that

supple current
#

yeah

#

which is how KSP works for anything that's "on rails"

#

("on rails" = kepler, "off rails" = newton)

rose pilot
#

what do you mean by "off rails"?

supple current
#

means that PhysX runs the show

mortal valve
supple current
#

not quite. he derived (or proved) the inverse-square law of the force acting on the bodies, and proposed that it was the same force that made an object fall to the ground

#

(though that might be knitting picks)

topaz owl
#

newbie here nevermind epicc

wary flume
supple current
#

for more than two bodies: no

wary flume
wary flume
#

thats intresting

#

ig it makes sense

#

orbits are parabolic

#

but idk why

supple current
#

get your hands on Feynman's Lost Lecture (or watch the 3b1b vid)

wary flume
#

ok

supple current
#

hmm, except, I can't find the vid

#

(maybe colab, or maybe I just can't identify it)

#

not the vid, but equally interesting (and rather relevant): https://www.youtube.com/watch?v=pQa_tWZmlGs

Dandelin spheres, conic sections, and a view of genius in math.
Help fund future projects: https://www.patreon.com/3blue1brown
An equally valuable form of support is to simply share some of the videos.
Special thanks to these supporters: http://3b1b.co/dandelin-thanks
Home page: https://www.3blue1brown.com

Thoughts on the recent change to be sp...

▶ Play video
ornate copper
west osprey
rose pilot
#

(also youtube XD)