Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Changed angle_between_vectors implementation to work for 3d vectors

Grant Sandersonbf0e3ab1b03b
diff --git a/manimlib/utils/space_ops.py b/manimlib/utils/space_ops.py
index 959fd198a..196707ca2 100644
--- a/manimlib/utils/space_ops.py
+++ b/manimlib/utils/space_ops.py
@@ -7,6 +7,7 @@ from manimlib.constants import PI
from manimlib.constants import RIGHT
from manimlib.constants import TAU
from manimlib.utils.iterables import adjacent_pairs
+from manimlib.utils.simple_functions import fdiv
def get_norm(vect):
@@ -140,10 +141,12 @@ def angle_of_vector(vector):
def angle_between_vectors(v1, v2):
"""
Returns the angle between two 3D vectors.
- This angle will always be btw 0 and TAU/2.
+ This angle will always be btw 0 and pi
"""
- diff = (angle_of_vector(v1) - angle_of_vector(v2)) % TAU
- return min(diff, TAU - diff)
+ return np.arccos(fdiv(
+ np.dot(v1, v2),
+ get_norm(v1) * get_norm(v2)
+ ))
def project_along_vector(point, vector):