Hypocycloid

In geometry, a hypocycloid is a plane curve generated by tracing the path of a point on the circumference of a smaller circle that rolls without slipping within a larger circle.

About

Setup

Create a new Colab notebook at colab.new and run the cells below.

The session will restart to apply changes.

%pip install mscene
import mscene
%mscene -l manim plugins
from mscene.manim import *
from mscene.plugins import *

Actions

The hypotrochoid_scene function animates hypocycloid or hypotrochoid scenes. A hypocycloid is a special case of hypotrochoid where the tracing point is on the circumference of the rolling circle.

def hypotrochoid_scene(
    scene,
    k,
    angle=-TAU,
    run_time=4,
    markers=[(1, PI / 2, ManimColor("#6019E3"))],
    scale=1,
    title=None,
):
    """Animates hypocycloid or hypotrochoid scenes. A hypocycloid is a special case of hypotrochoid where the tracing point is on the circumference of the rolling circle.

    Args:
        scene (Scene): An instance of Manim Scene for animation.
        k (float): The ratio R/r, where R is the radius of the fixed circle and r is the radius of the rolling circle. This affects the shape of the curve.
        angle (float): The angle of rotation around the fixed circle. Defaults to -TAU.
        run_time (float): The duration of rolling animation. Defaults to 4.
        markers (list[tuple[float, float, ManimColor]]): A list of markers for tracing the path, where each marker is a tuple of distance, angle and color. Defaults to [(1, PI / 2, ManimColor("#6019E3"))].
        scale (float): The scale factor to fit the scene within the frame. Defaults to 1.
        title (str | None, optional): The title of the scene. If not provided (None), no title will be shown. Defaults to None.

    Returns:
        None
    """

    h = config.frame_height * scale * 3 / 8
    r = h / k

    wheel = Wheel(radius=r, color=ManimColor("#04D9FF"), markers=markers)

    circle = Circle(radius=k * r, color=ManimColor("#6F828A"))

    txt = f"k = {k}" if title is None else f"{title}\nk = {k}"
    text = Text(txt).to_corner(UL, buff=2 / 3)

    wheel.move(circle.get_top(), DOWN)

    scene.play(FadeIn(text, circle, wheel))
    scene.wait(0.5)

    path = wheel.trace_paths()
    scene.add(path)

    scene.play(wheel.roll(angle, about=circle, run_time=run_time))

    path.clear_updaters()
    scene.wait(2)

    scene.play(FadeOut(path))
    scene.wait()

    scene.play(FadeOut(text, circle, wheel))
    scene.wait(0.5)

Scenes

Hypocycloid

%%manim -qm Hypocycloid
class Hypocycloid(Scene):
    def construct(self):

        hypotrochoid_scene(self, k=3, angle=-TAU, title="Hypocycloid")

Hypotrochoids

%%manim -qm Hypotrochoids
class Hypotrochoids(Scene):
    def construct(self):

        k, angle, run_time = (3, -TAU, 5)
        markers = [
            (2, PI / 2, ManimColor("#6019E3")),
            (0.5, -PI / 2, ManimColor("#E31937")),
        ]

        hypotrochoid_scene(self, k, angle, run_time, markers, scale=0.875)

Straight Lines

%%manim -qm StraightLines
class StraightLines(Scene):
    def construct(self):

        k, angle, run_time = (2, -2 * TAU, 8)
        markers = [
            (1, 0, ManimColor("#6019E3")),
            (1, PI / 2, ManimColor("#8C19AA")),
            (1, PI, ManimColor("#E31937")),
            (1, -PI / 2, ManimColor("#B71970")),
        ]

        hypotrochoid_scene(self, k, angle, run_time, markers)

Ellipses

%%manim -qm Ellipses
class Ellipses(Scene):
    def construct(self):

        k, angle, run_time = (2, -2 * TAU, 8)
        markers = [
            (2, 0, ManimColor("#6019E3")),
            (0.5, PI, ManimColor("#E31937")),
        ]

        hypotrochoid_scene(self, k, angle, run_time, markers, scale=0.9)