Skip to content

Instantly share code, notes, and snippets.

@VitamintK
Created January 19, 2021 22:05
Show Gist options
  • Save VitamintK/6b50f1b61625537e4e26da8acd72fa01 to your computer and use it in GitHub Desktop.
Save VitamintK/6b50f1b61625537e4e26da8acd72fa01 to your computer and use it in GitHub Desktop.
trying to visualize tides/tidal forces/gravity/why there are two high tides on earth
from manim import *
import math
dots_per_row = 120
moon = (10,0)
m2 = 10
G = 1
class MovingDot(Dot):
def __init__(self, *args, **kwargs):
self.velocity = [0,0]
super().__init__(*args, **kwargs)
class Gravity(MovingCameraScene):
def construct(self):
dots = []
for i in range(dots_per_row):
i = (i-dots_per_row//2)*(7/(dots_per_row//2))
for j in range(dots_per_row):
j = (j-dots_per_row//2)*(7/(dots_per_row//2))
if i*i+j*j >= 3:
continue
dots.append(MovingDot([i,j, 0], radius=0.05))
self.add(*dots)
self.wait(1)
def get_update_dot(acceleration):
def update_dot(dot, dt):
for i in range(len(acceleration)):
dot.velocity[i] += acceleration[i] * dt
dot.shift([i*dt for i in dot.velocity]+[0])
return update_dot
for dot in dots:
a = G * m2 / moon[0]
dotx, doty, _ = dot.get_center()
moonx, moony = moon
dx, dy = moonx-dotx, moony-doty
dist = math.sqrt(dx*dx+dy*dy)
scale = 1/dist
dx, dy = dx*scale, dy*scale
dot.add_updater(get_update_dot((dx,dy)))
# self.play(self.camera_frame.animate.set_width(20))
def update_cam(mob):
mob.move_to(dots[len(dots)//2].get_center())
# self.camera_frame.add_updater(update_cam)
self.wait(2)
@VitamintK
Copy link
Author

VitamintK commented Jan 19, 2021

# self.camera_frame.add_updater(update_cam)
uncommenting this line centers the camera on earth and the resulting animation will show the acceleration which would be imparted by the tidal force

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment