A community-maintained Python framework for creating mathematical animations.
Rewrite `put_start_and_end_on` to work in 3D (#1355)
Darylgoldena3faf1c9f1a8
diff --git a/manim/mobject/geometry.py b/manim/mobject/geometry.pyindex a1d17c816..de2838965 100644--- a/manim/mobject/geometry.py+++ b/manim/mobject/geometry.py@@ -1159,8 +1159,9 @@ class Arrow(Line):>>> arrow = Arrow(np.array([-1, -1, 0]), np.array([1, 1, 0]), buff=0)>>> scaled_arrow = arrow.scale(2)- >>> scaled_arrow.get_start_and_end()- (array([-2., -2., 0.]), array([2., 2., 0.]))+ >>> np.round(scaled_arrow.get_start_and_end(), 8) + 0+ array([[-2., -2., 0.],+ [ 2., 2., 0.]])>>> arrow.tip.length == scaled_arrow.tip.lengthTruediff --git a/manim/mobject/mobject.py b/manim/mobject/mobject.pyindex e4cb8f0e3..36e35d92a 100644--- a/manim/mobject/mobject.py+++ b/manim/mobject/mobject.py@@ -33,7 +33,9 @@ from ..utils.iterables import list_update, remove_list_redundanciesfrom ..utils.paths import straight_pathfrom ..utils.simple_functions import get_parametersfrom ..utils.space_ops import (+ angle_between_vectors,angle_of_vector,+ normalize,rotation_matrix,rotation_matrix_transpose,)@@ -1527,13 +1529,19 @@ class Mobject(Container):if np.all(curr_vect == 0):raise Exception("Cannot position endpoints of closed loop")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/tests/control_data/graphical_units_data/threed/MovingVerticesTest.npz b/tests/control_data/graphical_units_data/threed/MovingVerticesTest.npznew file mode 100644index 000000000..efb925556Binary files /dev/null and b/tests/control_data/graphical_units_data/threed/MovingVerticesTest.npz differdiff --git a/tests/test_graphical_units/test_threed.py b/tests/test_graphical_units/test_threed.pyindex 2dfdab9e3..add14dc03 100644--- a/tests/test_graphical_units/test_threed.py+++ b/tests/test_graphical_units/test_threed.py@@ -76,6 +76,22 @@ class FixedInFrameMObjectTest(ThreeDScene):self.add(axes)+class MovingVerticesTest(ThreeDScene):+ def construct(self):+ self.set_camera_orientation(phi=75 * DEGREES, theta=30 * DEGREES)+ vertices = [1, 2, 3, 4]+ edges = [(1, 2), (2, 3), (3, 4), (1, 3), (1, 4)]+ g = Graph(vertices, edges)+ self.add(g)+ self.play(+ g[1].animate.move_to([1, 1, 1]),+ g[2].animate.move_to([-1, 1, 2]),+ g[3].animate.move_to([1, -1, -1]),+ g[4].animate.move_to([-1, -1, 0]),+ )+ self.wait()++MODULE_NAME = "threed"