Help with extremely large and extremely small numbers

I tried to make a gravity attraction formula for simulating orbits without using trig (i just used a ratio of 1 to apply force to x and y), but it fails to update "position" and instead returns NaN, is this type of project simply impossible using snap? Or am i doing something completely wrong?


was this supposed to be a + instead of a -? because it being a - causes it to be negative, and you can't take the square root of a negative number. (without going into imaginaries and all that)

Or maybe (ABS (... - ...)).

… or may be “/“ (Pythagoras turning in his grave)

First of all, you need a proper scale and measurement units.
Right now, distance is expressed as a pixel = 1m.
Mass as a kg = 6 *10^24?
Gravitational constant as 1.
A rough estimation: the massive planet attracts a player located 100 m from the center of gravity with the force ~6*10^20 [N].
With 1 [s] steps, 1 kg player will be accelerated to ~6*10^20 [m/s] after one iteration.
Do you see the problem?

It's not clear if you want exact simulation, so the Bignum library may be used and SI units. But this poses the problem with scaling to display. I tried once to show the solar system at an exact scale. Planets become subpixel dots lost on screen.
Or just a rough, game-like estimation, so the values should be fine-tuned to allow movement of the player few pixels at once.


:rofl:

Yeah, all i wanted was to see a change, so i set the constant extremely high although i found the mistakes (one of them was divide by zero as someone else here pointed out)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.