Skip to content

Commit 7edb2c3

Browse files
committed
Add docstring for .rotate()
1 parent 3c6a1ee commit 7edb2c3

File tree

3 files changed

+139
-9
lines changed

3 files changed

+139
-9
lines changed

docs/source/examples.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ Animations
299299
path.become(previous_path)
300300
path.add_updater(update_path)
301301
self.add(path, dot)
302-
self.play(Rotating(dot, radians=PI, about_point=RIGHT, run_time=2))
302+
self.play(Rotating(dot, angle=PI, about_point=RIGHT, run_time=2))
303303
self.wait()
304304
self.play(dot.animate.shift(UP))
305305
self.play(dot.animate.shift(LEFT))

manim/animation/rotation.py

+74-4
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,93 @@
1919

2020

2121
class Rotating(Animation):
22+
"""Animation that rotates a Mobject.
23+
24+
Parameters
25+
----------
26+
mobject
27+
The mobject to be rotated.
28+
angle
29+
The rotation angle in radians. Predefined constants such as ``DEGREES``
30+
can also be used to specify the angle in degrees.
31+
axis
32+
The rotation axis as a numpy vector.
33+
about_point
34+
The rotation center.
35+
about_edge
36+
If ``about_point`` is ``None``, this argument specifies
37+
the direction of the bounding box point to be taken as
38+
the rotation center.
39+
run_time
40+
The duration of the animation in seconds.
41+
rate_func
42+
The function defining the animation progress based on the relative
43+
runtime (see :mod:`~.rate_functions`) .
44+
**kwargs
45+
Additional keyword arguments passed to :class:`~.Animation`.
46+
47+
Examples
48+
--------
49+
.. manim:: RotatingDemo
50+
51+
class RotatingDemo(Scene):
52+
def construct(self):
53+
circle = Circle(radius=1, color=BLUE)
54+
line = Line(start=ORIGIN, end=RIGHT)
55+
arrow = Arrow(start=ORIGIN, end=RIGHT, buff=0, color=GOLD)
56+
vg = VGroup(circle,line,arrow)
57+
self.add(vg)
58+
anim_kw = {"about_point": arrow.get_start(), "run_time": 1}
59+
self.play(Rotating(arrow, 180*DEGREES, **anim_kw))
60+
self.play(Rotating(arrow, PI, **anim_kw))
61+
self.play(Rotating(vg, PI, about_point=RIGHT))
62+
self.play(Rotating(vg, PI, axis=UP, about_point=ORIGIN))
63+
self.play(Rotating(vg, PI, axis=RIGHT, about_edge=UP))
64+
self.play(vg.animate.move_to(ORIGIN))
65+
66+
.. manim:: RotatingDifferentAxis
67+
68+
class RotatingDifferentAxis(ThreeDScene):
69+
def construct(self):
70+
axes = ThreeDAxes()
71+
cube = Cube()
72+
arrow2d = Arrow(start=[0, -1.2, 1], end=[0, 1.2, 1], color=YELLOW_E)
73+
cube_group = VGroup(cube,arrow2d)
74+
self.set_camera_orientation(gamma=0, phi=40*DEGREES, theta=40*DEGREES)
75+
self.add(axes, cube_group)
76+
play_kw = {"run_time": 1.5}
77+
self.play(Rotating(cube_group, PI), **play_kw)
78+
self.play(Rotating(cube_group, PI, axis=UP), **play_kw)
79+
self.play(Rotating(cube_group, 180*DEGREES, axis=RIGHT), **play_kw)
80+
self.wait(0.5)
81+
82+
See also
83+
--------
84+
:class:`~.Rotate`, :meth:`~.Mobject.rotate`
85+
86+
"""
87+
2288
def __init__(
2389
self,
2490
mobject: Mobject,
91+
angle: np.ndarray = TAU,
2592
axis: np.ndarray = OUT,
26-
radians: np.ndarray = TAU,
2793
about_point: np.ndarray | None = None,
2894
about_edge: np.ndarray | None = None,
29-
run_time: float = 5,
95+
run_time: float = 2,
3096
rate_func: Callable[[float], float] = linear,
3197
**kwargs,
3298
) -> None:
3399
self.axis = axis
34-
self.radians = radians
100+
self.angle = angle
35101
self.about_point = about_point
36102
self.about_edge = about_edge
37103
super().__init__(mobject, run_time=run_time, rate_func=rate_func, **kwargs)
38104

39105
def interpolate_mobject(self, alpha: float) -> None:
40106
self.mobject.become(self.starting_mobject)
41107
self.mobject.rotate(
42-
self.rate_func(alpha) * self.radians,
108+
self.rate_func(alpha) * self.angle,
43109
axis=self.axis,
44110
about_point=self.about_point,
45111
about_edge=self.about_edge,
@@ -80,6 +146,10 @@ def construct(self):
80146
Rotate(Square(side_length=0.5), angle=2*PI, rate_func=linear),
81147
)
82148
149+
See also
150+
--------
151+
:class:`~.Rotating`, :meth:`~.Mobject.rotate`
152+
83153
"""
84154

85155
def __init__(

manim/mobject/mobject.py

+64-4
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,9 @@ def construct(self):
387387
will interpolate the :class:`~.Mobject` between its points prior to
388388
``.animate`` and its points after applying ``.animate`` to it. This may
389389
result in unexpected behavior when attempting to interpolate along paths,
390-
or rotations.
390+
or rotations (see :meth:`.rotate`).
391391
If you want animations to consider the points between, consider using
392-
:class:`~.ValueTracker` with updaters instead.
392+
:class:`~.ValueTracker` with updaters instead (see :meth:`.add_updater`).
393393
394394
"""
395395
return _AnimationBuilder(self)
@@ -1029,6 +1029,9 @@ def construct(self):
10291029
:meth:`get_updaters`
10301030
:meth:`remove_updater`
10311031
:class:`~.UpdateFromFunc`
1032+
:class:`~.Rotating`
1033+
:meth:`rotate`
1034+
:attr:`~.Mobject.animate`
10321035
"""
10331036
if index is None:
10341037
self.updaters.append(update_function)
@@ -1282,7 +1285,64 @@ def rotate(
12821285
about_point: Point3DLike | None = None,
12831286
**kwargs,
12841287
) -> Self:
1285-
"""Rotates the :class:`~.Mobject` about a certain point."""
1288+
"""Rotates the :class:`~.Mobject` around a specified axis and point.
1289+
1290+
Parameters
1291+
----------
1292+
angle
1293+
The angle of rotation in radians. Predefined constants such as ``DEGREES``
1294+
can also be used to specify the angle in degrees.
1295+
axis
1296+
The rotation axis (see :class:`~.Rotating` for more).
1297+
about_point
1298+
The point about which the mobject rotates. If ``None``, rotation occurs around
1299+
the center of the mobject.
1300+
**kwargs
1301+
Additional keyword arguments passed to :meth:`apply_points_function_about_point`,
1302+
such as ``about_edge``.
1303+
1304+
Returns
1305+
-------
1306+
:class:`Mobject`
1307+
``self`` (for method chaining)
1308+
1309+
1310+
.. note::
1311+
To animate a rotation, use :class:`~.Rotating` or :class:`~.Rotate`
1312+
instead of ``.animate.rotate(...)``.
1313+
The ``.animate.rotate(...)`` syntax only applies a transformation
1314+
from the initial state to the final rotated state
1315+
(interpolation between the two states), without showing proper rotational motion
1316+
based on the angle (from 0 to the given angle).
1317+
1318+
Examples
1319+
--------
1320+
1321+
.. manim:: RotateMethodExample
1322+
:save_last_frame:
1323+
1324+
class RotateMethodExample(Scene):
1325+
def construct(self):
1326+
circle = Circle(radius=1, color=BLUE)
1327+
line = Line(start=ORIGIN, end=RIGHT)
1328+
arrow1 = Arrow(start=ORIGIN, end=RIGHT, buff=0, color=GOLD)
1329+
group1 = VGroup(circle, line, arrow1)
1330+
1331+
group2 = group1.copy()
1332+
arrow2 = group2[2]
1333+
arrow2.rotate(angle=PI / 4, about_point=arrow2.get_start())
1334+
1335+
group3 = group1.copy()
1336+
arrow3 = group3[2]
1337+
arrow3.rotate(angle=120 * DEGREES, about_point=arrow3.get_start())
1338+
1339+
self.add(VGroup(group1, group2, group3).arrange(RIGHT, buff=1))
1340+
1341+
See also
1342+
--------
1343+
:class:`~.Rotating`, :class:`~.Rotate`, :attr:`~.Mobject.animate`, :meth:`apply_points_function_about_point`
1344+
1345+
"""
12861346
rot_matrix = rotation_matrix(angle, axis)
12871347
self.apply_points_function_about_point(
12881348
lambda points: np.dot(points, rot_matrix.T), about_point, **kwargs
@@ -3143,7 +3203,7 @@ def override_animate(method) -> types.FunctionType:
31433203
31443204
.. seealso::
31453205
3146-
:attr:`Mobject.animate`
3206+
:attr:`~.Mobject.animate`
31473207
31483208
.. note::
31493209

0 commit comments

Comments
 (0)