A community-maintained Python framework for creating mathematical animations.
Rewrite put_start_and_end_on for :class:`~.OpenGLMobject` to work correctly in 3D (#1770)
Darylgoldenfdc4c853a305
diff --git a/manim/mobject/opengl_mobject.py b/manim/mobject/opengl_mobject.pyindex 5cf0e05cd..3e17ae429 100644--- a/manim/mobject/opengl_mobject.py+++ b/manim/mobject/opengl_mobject.py@@ -25,7 +25,12 @@ from ..utils.iterables import ()from ..utils.paths import straight_pathfrom ..utils.simple_functions import get_parameters-from ..utils.space_ops import angle_of_vector, rotation_matrix_transpose+from ..utils.space_ops import (+ angle_between_vectors,+ angle_of_vector,+ normalize,+ rotation_matrix_transpose,+)class OpenGLMobject:@@ -961,19 +966,24 @@ class OpenGLMobject:return selfdef put_start_and_end_on(self, start, end):- # TODO, this doesn't currently work in 3dcurr_start, curr_end = self.get_start_and_end()curr_vect = curr_end - curr_startif np.all(curr_vect == 0):raise Exception("Cannot position endpoints of closed loop")- target_vect = end - start+ target_vect = np.array(end) - np.array(start)+ axis = (+ normalize(np.cross(curr_vect, target_vect))+ if np.linalg.norm(np.cross(curr_vect, target_vect)) != 0+ else OUT+ )self.scale(np.linalg.norm(target_vect) / np.linalg.norm(curr_vect),about_point=curr_start,)self.rotate(- angle_of_vector(target_vect) - angle_of_vector(curr_vect),+ angle_between_vectors(curr_vect, target_vect),about_point=curr_start,+ axis=axis,)self.shift(start - curr_start)return selfdiff --git a/manim/utils/space_ops.py b/manim/utils/space_ops.pyindex 35a468258..a675bd435 100644--- a/manim/utils/space_ops.py+++ b/manim/utils/space_ops.py@@ -351,14 +351,11 @@ def angle_between_vectors(v1: np.ndarray, v2: np.ndarray) -> np.ndarray:np.ndarrayThe angle between the vectors."""- if config["renderer"] == "opengl":- diff = (angle_of_vector(v2) - angle_of_vector(v1)) % TAU- return min(diff, TAU - diff)- else:- return 2 * np.arctan2(- np.linalg.norm(normalize(v1) - normalize(v2)),- np.linalg.norm(normalize(v1) + normalize(v2)),- )++ return 2 * np.arctan2(+ np.linalg.norm(normalize(v1) - normalize(v2)),+ np.linalg.norm(normalize(v1) + normalize(v2)),+ )def project_along_vector(point: float, vector: np.ndarray) -> np.ndarray: