xparq / Out_of_Nothing

Versatile entity-based simulation & visualization/gamification framework PROTOTYPE
0 stars 0 forks source link

The "Realistic" gravity calc. seems way off #525

Closed xparq closed 6 months ago

xparq commented 7 months ago

Fixing the wrong exponent of distance, which has been

    float a_target = gravity * source->mass / (distance * distance);
    Vector2f dv_target = Vector2f{dx * a_target, dy * a_target} * dt;

but shoulda been

    ...
    Vector2f dv_target = Vector2f{dx/distance * a_target, dy/distance * a_target} * dt;

just results in virtually no gravity at all! :-o Spawning 100 densely packed objects just stand still.

Zoomed in, time accelerated 64x, and then finally there's some teeny-tiny movement. I'd imagine planet-sized bodies attracting each other a lot more than that, when they are very near. And I can see nothing like the usual accelerations of free-falling to Earth, even though some objects are many 100x times heavier than Earth!

Or is it still somehow what would happen IRL, and it would take gigantic stars, not planets, to actually be funny? (I've just seen a cool -- and very dynamic -- planet collision simulation about the birth of the Moon, for instance, but dunno if that was real-time.)


Might still be a float precision issue!

Anyhow, food for thought:

1234567 + 1: 1234568
12345678 + 1: 12345679
123456789 + 1: 123456792
1234567890 + 1: 1.23456794e+09
12345678901 + 1: 1.23456788e+10
123456789012 + 1: 1.23456791e+11

UPDATE:

OK, after using double, fixing the sign bug, and then more digging, plus double-checking some calcs., it seems that real-life gravity really is just no fun! :) Things only happen on cosmic time scales...

xparq commented 7 months ago

Some handy real-life data:

xparq commented 6 months ago

Just the record of some manual calcs. to check things... (All in meters.)

PLANET: (161.6 x Earth) X ; Y = -2,602,161 ; 9,432,115 VX ; VY = -0.1731978 ; 0.005617

MOON: (39.8 x Earth) X ; Y = 675,572,512 ; -12,564,107 VX ; VY = -0.703406 ; 0.02281

Distance = SQRT(672,970,351^2 + -3,131,992^2) = SQRT(452,889,093,325,063,201 + 9,809,373,888,064) = 672,977,639

F = 33,806,294,475,506,309,669,097,119 N (checked OK: 34,099,773,542,273,339,786,177,572) gP = F/M = 0.0352 m/s^2 gM = F/m = 0.1428 m/s^2

BTW, the Moon feels an even smaller g, and it would take ~5 days to fall into Earth if stopped orbiting. :)

xparq commented 6 months ago

OK, after using double, fixing the sign bug, and then more digging, experimenting (a lot) more, plus double-checking some calcs. etc., it seems that real-life gravity really is just no fun! :) Things only happen on cosmic time scales...