Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Add parameter `about_point` for `rotate` (#1238)

kolibril135017a4943a9a
diff --git a/manim/mobject/mobject.py b/manim/mobject/mobject.py
index a93183627..33a7605df 100644
--- a/manim/mobject/mobject.py
+++ b/manim/mobject/mobject.py
@@ -1055,18 +1055,24 @@ class Mobject(Container):
"""Rotates the :class:`~.Mobject` about the ORIGIN, which is at [0,0,0]."""
return self.rotate(angle, axis, about_point=ORIGIN)
- def rotate(self, angle, axis=OUT, **kwargs):
+ def rotate(
+ self,
+ angle,
+ axis=OUT,
+ about_point: Union[np.ndarray, List, None] = None,
+ **kwargs,
+ ):
"""Rotates the :class:`~.Mobject` about a certain point."""
if config.renderer == "opengl":
rot_matrix_T = rotation_matrix_transpose(angle, axis)
self.apply_points_function(
- lambda points: np.dot(points, rot_matrix_T), **kwargs
+ lambda points: np.dot(points, rot_matrix_T), about_point, **kwargs
)
return self
else:
rot_matrix = rotation_matrix(angle, axis)
self.apply_points_function_about_point(
- lambda points: np.dot(points, rot_matrix.T), **kwargs
+ lambda points: np.dot(points, rot_matrix.T), about_point, **kwargs
)
return self
diff --git a/manim/mobject/opengl_mobject.py b/manim/mobject/opengl_mobject.py
index 01b715ea2..23df0e452 100644
--- a/manim/mobject/opengl_mobject.py
+++ b/manim/mobject/opengl_mobject.py
@@ -3,6 +3,7 @@ import itertools as it
import random
import sys
from functools import wraps
+from typing import List, Union
import moderngl
import numpy as np
@@ -56,7 +57,7 @@ class OpenGLMobject:
# Must match in attributes of vert shader
# Event listener
listen_to_events=False,
- **kwargs
+ **kwargs,
):
self.color = color
@@ -614,7 +615,13 @@ class OpenGLMobject:
def rotate_about_origin(self, angle, axis=OUT):
return self.rotate(angle, axis, about_point=ORIGIN)
- def rotate(self, angle, axis=OUT, **kwargs):
+ def rotate(
+ self,
+ angle,
+ axis=OUT,
+ about_point: Union[np.ndarray, List, None] = None,
+ **kwargs,
+ ):
rot_matrix_T = rotation_matrix_transpose(angle, axis)
self.apply_points_function(
lambda points: np.dot(points, rot_matrix_T), **kwargs
@@ -1404,7 +1411,7 @@ class OpenGLMobject:
def get_shader_wrapper_list(self):
shader_wrappers = it.chain(
[self.get_shader_wrapper()],
- *[sm.get_shader_wrapper_list() for sm in self.submobjects]
+ *[sm.get_shader_wrapper_list() for sm in self.submobjects],
)
batches = batch_by_property(shader_wrappers, lambda sw: sw.get_id())