Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Fixed :class:`~.Rotate` for angles that are multiples of :math:`2\pi` (#1938)

sparshgec081d1ef594
diff --git a/manim/animation/rotation.py b/manim/animation/rotation.py
index 043b4349b..d8236c638 100644
--- a/manim/animation/rotation.py
+++ b/manim/animation/rotation.py
@@ -62,7 +62,9 @@ class Rotate(Transform):
self.axis = axis
self.about_edge = about_edge
self.about_point = about_point
- super().__init__(mobject, **kwargs)
+ if self.about_point is None:
+ self.about_point = mobject.get_center()
+ super().__init__(mobject, path_arc_centers=self.about_point, **kwargs)
def create_target(self) -> "Mobject":
target = self.mobject.copy()
diff --git a/manim/animation/transform.py b/manim/animation/transform.py
index 1e3fc91f4..61a719acc 100644
--- a/manim/animation/transform.py
+++ b/manim/animation/transform.py
@@ -50,10 +50,12 @@ class Transform(Animation):
path_func: Optional[Callable] = None,
path_arc: float = 0,
path_arc_axis: np.ndarray = OUT,
+ path_arc_centers: np.ndarray = None,
replace_mobject_with_target_in_scene: bool = False,
**kwargs,
) -> None:
self.path_arc_axis: np.ndarray = path_arc_axis
+ self.path_arc_centers: np.ndarray = path_arc_centers
self.path_arc: float = path_arc
self.path_func: Optional[Callable] = path_func
self.replace_mobject_with_target_in_scene: bool = (
@@ -71,7 +73,11 @@ class Transform(Animation):
@path_arc.setter
def path_arc(self, path_arc: float) -> None:
self._path_arc = path_arc
- self._path_func = path_along_arc(self._path_arc, self.path_arc_axis)
+ self._path_func = path_along_arc(
+ arc_angle=self._path_arc,
+ axis=self.path_arc_axis,
+ arc_centers=self.path_arc_centers,
+ )
@property
def path_func(
diff --git a/manim/utils/paths.py b/manim/utils/paths.py
index efa9044ca..eae38998e 100644
--- a/manim/utils/paths.py
+++ b/manim/utils/paths.py
@@ -27,7 +27,7 @@ def straight_path(start_points, end_points, alpha):
return interpolate(start_points, end_points, alpha)
-def path_along_arc(arc_angle, axis=OUT):
+def path_along_arc(arc_angle, axis=OUT, arc_centers=None):
"""
If vect is vector from start to end, [vect[:,1], -vect[:,0]] is
perpendicular to vect in the left direction.
@@ -39,10 +39,13 @@ def path_along_arc(arc_angle, axis=OUT):
unit_axis = axis / np.linalg.norm(axis)
def path(start_points, end_points, alpha):
- vects = end_points - start_points
- centers = start_points + 0.5 * vects
- if arc_angle != np.pi:
- centers += np.cross(unit_axis, vects / 2.0) / np.tan(arc_angle / 2)
+ if arc_centers is None:
+ vects = end_points - start_points
+ centers = start_points + 0.5 * vects
+ if arc_angle != np.pi:
+ centers += np.cross(unit_axis, vects / 2.0) / np.tan(arc_angle / 2)
+ else:
+ centers = arc_centers
rot_matrix = rotation_matrix(alpha * arc_angle, unit_axis)
return centers + np.dot(start_points - centers, rot_matrix.T)
diff --git a/tests/control_data/graphical_units_data/transform/FullRotation.npz b/tests/control_data/graphical_units_data/transform/FullRotation.npz
new file mode 100644
index 000000000..f273625af
Binary files /dev/null and b/tests/control_data/graphical_units_data/transform/FullRotation.npz differ
diff --git a/tests/test_graphical_units/test_transform.py b/tests/test_graphical_units/test_transform.py
index 8056578f0..8e76e6361 100644
--- a/tests/test_graphical_units/test_transform.py
+++ b/tests/test_graphical_units/test_transform.py
@@ -18,6 +18,17 @@ def test_TransformFromCopy(scene):
scene.play(TransformFromCopy(square, circle))
+@frames_comparison(last_frame=False)
+def test_FullRotation(scene):
+ s = VGroup(*[Square() for _ in range(4)]).arrange()
+ scene.play(
+ Rotate(s[0], -2 * TAU),
+ Rotate(s[1], -1 * TAU),
+ Rotate(s[2], 1 * TAU),
+ Rotate(s[3], 2 * TAU),
+ )
+
+
@frames_comparison(last_frame=False)
def test_ClockwiseTransform(scene):
square = Square()