Skip to content

Instantly share code, notes, and snippets.

@uwezi
Last active February 17, 2025 23:16
Show Gist options
  • Save uwezi/1e8d257946fb25e32bb430022bd86294 to your computer and use it in GitHub Desktop.
Save uwezi/1e8d257946fb25e32bb430022bd86294 to your computer and use it in GitHub Desktop.
[Planetary gear] A planetary gear animation. #manim #animation #geometry #gears #mechanics
from manim_gearbox import *
class PlanetaryGears(Scene):
def construct(self):
# https://en.wikipedia.org/wiki/Epicyclic_gearing#Gear_speed_ratios_of_conventional_epicyclic_gearing
omegaplanet = 0.44
omegacarrier = 0.44*10/15
omegaring = (15+35)/35*omegacarrier
module = 0.15 # diameter = module * number of teeth
# Create the sun gear (center gear)
sun_gear = Gear(
15, stroke_opacity=0, fill_color=YELLOW, fill_opacity=1, module=module # 15 teeth
)
# Create the ring gear (outer gear)
ring_gear = Gear(
35, module=module, inner_teeth=True, stroke_opacity=0, fill_color=RED, fill_opacity=1,
)
# Create the planetary gears and position them
def planetUpdater(mobj,dt):
mobj.rotate(dt*omegaplanet, about_point=mobj.get_center())
def carrierUpdater(mobj,dt):
mobj.rotate(dt*omegacarrier, about_point=mobj.get_center())
def ringUpdater(mobj,dt):
mobj.rotate(dt*omegaring, about_point=mobj.get_center())
ring_gear.add_updater(ringUpdater)
carrier_frame = VGroup()
for dir in (LEFT, RIGHT):
gear = Gear(
10, stroke_opacity=0, fill_color=BLUE, fill_opacity=1, module=module
).next_to(sun_gear, dir)
gear.add_updater(planetUpdater)
gear.mesh_to(sun_gear) # Connect the planet gear to the sun gear
ring_gear.mesh_to(gear) # Connect the planet gear to the ring gear
carrier_frame.add(gear)
carrier_frame.add_updater(carrierUpdater)
self.add(sun_gear,ring_gear,carrier_frame)
self.wait(8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment