mirror of
https://github.com/3b1b/manim.git
synced 2025-09-01 00:48:45 +00:00
In rotation_between_vectors, account for the case where vectors align
This commit is contained in:
parent
c36d178856
commit
baf2690d77
1 changed files with 9 additions and 2 deletions
|
@ -10,7 +10,7 @@ import numpy as np
|
||||||
from scipy.spatial.transform import Rotation
|
from scipy.spatial.transform import Rotation
|
||||||
from tqdm import tqdm as ProgressDisplay
|
from tqdm import tqdm as ProgressDisplay
|
||||||
|
|
||||||
from manimlib.constants import DOWN, OUT, RIGHT
|
from manimlib.constants import DOWN, OUT, RIGHT, UP
|
||||||
from manimlib.constants import PI, TAU
|
from manimlib.constants import PI, TAU
|
||||||
from manimlib.utils.iterables import adjacent_pairs
|
from manimlib.utils.iterables import adjacent_pairs
|
||||||
from manimlib.utils.simple_functions import clip
|
from manimlib.utils.simple_functions import clip
|
||||||
|
@ -134,8 +134,15 @@ def rotation_about_z(angle: float) -> Matrix3x3:
|
||||||
|
|
||||||
|
|
||||||
def rotation_between_vectors(v1: Vect3, v2: Vect3) -> Matrix3x3:
|
def rotation_between_vectors(v1: Vect3, v2: Vect3) -> Matrix3x3:
|
||||||
if np.all(np.isclose(v1, v2)):
|
if np.isclose(v1, v2).all():
|
||||||
return np.identity(3)
|
return np.identity(3)
|
||||||
|
axis = np.cross(v1, v2)
|
||||||
|
if np.isclose(axis, [0, 0, 0]).all():
|
||||||
|
# v1 and v2 align
|
||||||
|
axis = np.cross(v1, RIGHT)
|
||||||
|
if np.isclose(axis, [0, 0, 0]).all():
|
||||||
|
# v1 and v2 _and_ RIGHT all align
|
||||||
|
axis = np.cross(v1, UP)
|
||||||
return rotation_matrix(
|
return rotation_matrix(
|
||||||
angle=angle_between_vectors(v1, v2),
|
angle=angle_between_vectors(v1, v2),
|
||||||
axis=np.cross(v1, v2)
|
axis=np.cross(v1, v2)
|
||||||
|
|
Loading…
Add table
Reference in a new issue