May 31, 2022
Gravity simulation for the kids

https://gist.github.com/akkartik/001dcd31aa0e042df0b0a0408f99d742

It's amazing how short the core of Newton's law of gravity is:

theta = angle(sun.x,sun.y, sat.x, sat.y)
dist = distance(sun.x,sun.y, sat.x,sat.y)
accelx = K*cos(theta)/dist/dist
accely = K*sin(theta)/dist/dist
velx = velx + dt*accelx
vely = vely + dt*accely
posx = posx + velx
posy = posy + vely
plot(posx,posy)

This post is part of my Freewheeling Apps Devlog.

Comments gratefully appreciated. Please send them to me by any method of your choice and I'll include them here.

archive
projects
writings
videos
subscribe
Mastodon
RSS (?)
twtxt (?)
Station (?)