How to arrange and animate a frilled line along a torus shape in Manim?

22 hours ago 1
ARTICLE AD BOX

Target: Arrange and Animate a Frilled Line along a Torus in Manim

Answer:

The primary challenge here is mapping a 1D parametric function (the frilled line) onto a 3D surface (the torus) while maintaining the "frill" (high-frequency oscillation) relative to the surface normal. In Manim, the most deterministic approach is to define a composite parametric function.

Use the following implementation. It uses a Surface to define the torus and a ParametricFunction that adds a sine-wave displacement (the frill) to the torus coordinates.

Python

# [Logic Hardening] Parametric Torus Mapping with Frequency Displacement from manim import * import numpy as np class FrilledTorus(ThreeDScene): def construct(self): # Torus parameters R, r = 3, 1 # Major and minor radii frill_amplitude = 0.2 frill_frequency = 40 # Number of frills along the loop # [Logic Point] Composite Parametric Mapping def frilled_torus_func(t): # Base torus coordinates # t moves from 0 to 2*PI x = (R + r * np.cos(t)) * np.cos(t * 0.1) # Slowly rotating loop y = (R + r * np.cos(t)) * np.sin(t * 0.1) z = r * np.sin(t) # Adding the 'frill' displacement # We oscillate the minor radius 'r' to create the frilled effect distorted_r = r + frill_amplitude * np.sin(frill_frequency * t) x_f = (R + distorted_r * np.cos(t)) * np.cos(t) y_f = (R + distorted_r * np.cos(t)) * np.sin(t) z_f = distorted_r * np.sin(t) return np.array([x_f, y_f, z_f]) frilled_line = ParametricFunction( frilled_torus_func, t_range=[0, TAU], color=YELLOW ) # Scene Setup axes = ThreeDAxes() self.set_camera_orientation(phi=75 * DEGREES, theta=-45 * DEGREES) self.add(axes) # [Logic Point] Animating the creation along the 3D path self.play(Create(frilled_line), run_time=4, rate_func=linear) self.begin_ambient_camera_rotation(rate=0.1) self.wait(2)

Note:

Coordinate Logic: The distorted_r variable injects the "frill" directly into the minor radius calculation, ensuring the frills point outward from the torus center.

Frequency: Adjust frill_frequency to increase the density of the frills.

Refactor: Ensure your R and r match the scale of your existing Manim scene.

Y. Cheng Zhang's user avatar

New contributor

Y. Cheng Zhang is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

Read Entire Article