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.pyindex 043b4349b..d8236c638 100644--- a/manim/animation/rotation.py+++ b/manim/animation/rotation.py@@ -62,7 +62,9 @@ class Rotate(Transform):self.axis = axisself.about_edge = about_edgeself.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.pyindex 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_centersself.path_arc: float = path_arcself.path_func: Optional[Callable] = path_funcself.replace_mobject_with_target_in_scene: bool = (@@ -71,7 +73,11 @@ class Transform(Animation):@path_arc.setterdef 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,+ )@propertydef path_func(diff --git a/manim/utils/paths.py b/manim/utils/paths.pyindex 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]] isperpendicular 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_centersrot_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.npznew file mode 100644index 000000000..f273625afBinary files /dev/null and b/tests/control_data/graphical_units_data/transform/FullRotation.npz differdiff --git a/tests/test_graphical_units/test_transform.py b/tests/test_graphical_units/test_transform.pyindex 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()