Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Normalize the direction vector in always_shift() (#839)

Devin Neal8f191f9d96f1
diff --git a/manim/mobject/mobject_update_utils.py b/manim/mobject/mobject_update_utils.py
index 5d6692fc8..ff4d94368 100644
--- a/manim/mobject/mobject_update_utils.py
+++ b/manim/mobject/mobject_update_utils.py
@@ -59,7 +59,13 @@ def always_redraw(func):
def always_shift(mobject, direction=RIGHT, rate=0.1):
- mobject.add_updater(lambda m, dt: m.shift(dt * rate * direction))
+ def normalize(v):
+ norm = np.linalg.norm(v)
+ if norm == 0:
+ return v
+ return v / norm
+
+ mobject.add_updater(lambda m, dt: m.shift(dt * rate * normalize(direction)))
return mobject