Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Added ``about_point`` keyword argument to :class:`~.ApplyMatrix` (#2388)

Jihoonb6f7acf0e154
diff --git a/manim/animation/transform.py b/manim/animation/transform.py
index cfdfa4d93..b2dac452a 100644
--- a/manim/animation/transform.py
+++ b/manim/animation/transform.py
@@ -32,7 +32,7 @@ import numpy as np
from .. import config
from ..animation.animation import Animation
-from ..constants import DEFAULT_POINTWISE_FUNCTION_RUN_TIME, DEGREES, OUT
+from ..constants import DEFAULT_POINTWISE_FUNCTION_RUN_TIME, DEGREES, ORIGIN, OUT
from ..mobject.mobject import Group, Mobject
from ..mobject.opengl_mobject import OpenGLGroup, OpenGLMobject
from ..utils.paths import path_along_arc, path_along_circles
@@ -381,11 +381,31 @@ class ApplyFunction(Transform):
class ApplyMatrix(ApplyPointwiseFunction):
- def __init__(self, matrix: np.ndarray, mobject: Mobject, **kwargs) -> None:
+ """Applies a matrix transform to an mobject.
+
+ Parameters
+ ----------
+ matrix
+ The transformation matrix.
+ mobject
+ The :class:`~.Mobject`.
+ about_point
+ The origin point for the transform. Defaults to ``ORIGIN``.
+ kwargs
+ Further keyword arguments that are passed to :class:`ApplyPointwiseFunction`.
+ """
+
+ def __init__(
+ self,
+ matrix: np.ndarray,
+ mobject: Mobject,
+ about_point: np.ndarray = ORIGIN,
+ **kwargs,
+ ) -> None:
matrix = self.initialize_matrix(matrix)
def func(p):
- return np.dot(p, matrix.T)
+ return np.dot(p - about_point, matrix.T) + about_point
super().__init__(func, mobject, **kwargs)
diff --git a/tests/test_graphical_units/control_data/transform/ApplyMatrix.npz b/tests/test_graphical_units/control_data/transform/ApplyMatrix.npz
index e1d0914e5..1350affd3 100644
Binary files a/tests/test_graphical_units/control_data/transform/ApplyMatrix.npz and b/tests/test_graphical_units/control_data/transform/ApplyMatrix.npz differ
diff --git a/tests/test_graphical_units/test_transform.py b/tests/test_graphical_units/test_transform.py
index ca2699ae0..667139e98 100644
--- a/tests/test_graphical_units/test_transform.py
+++ b/tests/test_graphical_units/test_transform.py
@@ -119,7 +119,8 @@ def test_ApplyComplexFunction(scene):
def test_ApplyMatrix(scene):
square = Square()
matrice = [[1.0, 0.5], [1.0, 0.0]]
- scene.play(ApplyMatrix(matrice, square))
+ about_point = np.asarray((-10.0, 5.0, 0.0))
+ scene.play(ApplyMatrix(matrice, square, about_point))
@frames_comparison(last_frame=False)