mirror of
https://github.com/3b1b/manim.git
synced 2025-08-31 23:58:32 +00:00
Changed angle_between_vectors implementation to work for 3d vectors
This commit is contained in:
parent
7a488702e4
commit
bf0e3ab1b0
1 changed files with 6 additions and 3 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Reference in a new issue