Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Made arrow tips rotate up/down (#1924)

icedcoffeeeefba4baef65ac
diff --git a/manim/mobject/geometry.py b/manim/mobject/geometry.py
index 28783e404..20711dac8 100644
--- a/manim/mobject/geometry.py
+++ b/manim/mobject/geometry.py
@@ -85,6 +85,7 @@ from ..utils.iterables import adjacent_n_tuples, adjacent_pairs
from ..utils.space_ops import (
angle_between_vectors,
angle_of_vector,
+ cartesian_to_spherical,
line_intersection,
normalize,
perpendicular_bisector,
@@ -176,7 +177,18 @@ class TipableVMobject(VMobject, metaclass=ConvertToOpenGL):
else:
handle = self.get_last_handle()
anchor = self.get_end()
- tip.rotate(angle_of_vector(handle - anchor) - PI - tip.tip_angle)
+ angles = cartesian_to_spherical(handle - anchor)
+ tip.rotate(
+ angles[2] - PI - tip.tip_angle
+ ) # Rotates the tip along the azimuthal
+ axis = [
+ np.sin(angles[2]),
+ -np.cos(angles[2]),
+ 0,
+ ] # Obtains the perpendicular of the tip
+ tip.rotate(
+ -angles[1] + PI / 2, axis=axis
+ ) # Rotates the tip along the vertical wrt the axis
tip.shift(anchor - tip.tip_point)
return tip
@@ -1468,7 +1480,7 @@ class Arrow(Line):
--------
::
- >>> Arrow().get_normal_vector() + 0. # add 0. to avoid negative 0 in output
+ >>> np.round(Arrow().get_normal_vector()) + 0. # add 0. to avoid negative 0 in output
array([ 0., 0., -1.])
"""
diff --git a/tests/control_data/graphical_units_data/geometry/AngledArrowTip.npz b/tests/control_data/graphical_units_data/geometry/AngledArrowTip.npz
new file mode 100644
index 000000000..b58c267c9
Binary files /dev/null and b/tests/control_data/graphical_units_data/geometry/AngledArrowTip.npz differ
diff --git a/tests/test_graphical_units/test_geometry.py b/tests/test_graphical_units/test_geometry.py
index 1a362e72d..c451ed92e 100644
--- a/tests/test_graphical_units/test_geometry.py
+++ b/tests/test_graphical_units/test_geometry.py
@@ -194,3 +194,9 @@ def test_RegularPolygram(scene):
def test_Star(scene):
star = Star(outer_radius=2)
scene.add(star)
+
+
+@frames_comparison
+def test_AngledArrowTip(scene):
+ arrow = Arrow(start=ORIGIN, end=UP + RIGHT + OUT)
+ scene.add(arrow)