Skip to content

Instantly share code, notes, and snippets.

@uwezi
Last active March 31, 2025 12:14
Show Gist options
  • Save uwezi/66b8fcd2927ec278be8a0c6a289665d4 to your computer and use it in GitHub Desktop.
Save uwezi/66b8fcd2927ec278be8a0c6a289665d4 to your computer and use it in GitHub Desktop.
[Rationale] Visualization of e^(iθ)+e^(n iθ). #manim #animation #complex #math
# https://discord.com/channels/581738731934056449/585955412436713495/1312571596287774781
# https://youtube.com/shorts/dzjnM2EDDpE?si=_M8UHJR_ku6y2qIx
from manim import *
config.frame_rate=60
class compass2(Scene):
def construct(self):
l = 2
n = np.sqrt(2) # speed multiplier on second arm
θ = ValueTracker(0)
def Zfunc(x):
return np.exp(x * 1j)
def splitZ(Z):
return [Z.real,Z.imag]
Z1 = always_redraw(lambda:
Line(
ORIGIN,
l*np.array([
*splitZ(Zfunc(θ.get_value())),
0
]),
color=YELLOW,
)
)
Z2 = always_redraw(lambda:
Line(
ORIGIN,
l*np.array([
np.real(Zfunc(n*θ.get_value())),
np.imag(Zfunc(n*θ.get_value())),
0
]),
color=RED,
)
.shift(Z1.get_end())
)
self.add(Z1,Z2)
tpath = TracedPath(Z2.get_end, stroke_color=BLUE)
self.add(tpath)
self.play(
θ.animate.set_value(20*PI),
run_time=30,
rate_func=rate_functions.linear
)
self.wait()

bild

line 17-20 show one method to split the real and imaginary parts, lines 28-30 another Calling the exponentail function twice in the second method creates an unnecesssary overhead, but might be more didactic

n=2.3 bild

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