Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Fix successive calls of :meth:`.LinearTransformationScene.apply_matrix` (#3675)

Sir James Clark Maxwell27766127e266
diff --git a/manim/scene/vector_space_scene.py b/manim/scene/vector_space_scene.py
index d39ce3289..e9304115e 100644
--- a/manim/scene/vector_space_scene.py
+++ b/manim/scene/vector_space_scene.py
@@ -1003,8 +1003,11 @@ class LinearTransformationScene(VectorScene):
Animation
The animation of the movement.
"""
- start = VGroup(*pieces)
- target = VGroup(*(mob.target for mob in pieces))
+
+ v_pieces = [piece for piece in pieces if isinstance(piece, VMobject)]
+ start = VGroup(*v_pieces)
+ target = VGroup(*(mob.target for mob in v_pieces))
+
# don't add empty VGroups
if self.leave_ghost_vectors and start.submobjects:
# start.copy() gives a VGroup of Vectors
@@ -1091,6 +1094,7 @@ class LinearTransformationScene(VectorScene):
**kwargs
Any valid keyword argument of self.apply_transposed_matrix()
"""
+
self.apply_transposed_matrix(np.array(matrix).T, **kwargs)
def apply_inverse(self, matrix: np.ndarray | list | tuple, **kwargs):
diff --git a/tests/test_graphical_units/test_vector_scene.py b/tests/test_graphical_units/test_vector_scene.py
index 59dfda44a..75bc1806d 100644
--- a/tests/test_graphical_units/test_vector_scene.py
+++ b/tests/test_graphical_units/test_vector_scene.py
@@ -1,6 +1,6 @@
from __future__ import annotations
-from manim.scene.vector_space_scene import VectorScene
+from manim.scene.vector_space_scene import LinearTransformationScene, VectorScene
from manim.utils.testing.frames_comparison import frames_comparison
__module_test__ = "vector_scene"
@@ -14,3 +14,13 @@ def test_vector_to_coords(scene):
scene.add(basis)
scene.vector_to_coords(vector=vector)
scene.wait()
+
+
+def test_apply_matrix():
+ scene = LinearTransformationScene(include_background_plane=False)
+ scene.setup()
+ matrix = [[-1, 1], [1, 1]]
+ # use short runtimes to speed up animation rendering
+ scene.apply_matrix(matrix, run_time=0.01)
+ scene.wait()
+ scene.apply_inverse(matrix, run_time=0.01)