From b2137f2746ccbfabfffba98b60f6ed639322f1e8 Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Fri, 5 Jun 2020 13:21:35 -0700 Subject: [PATCH] Fixed z_to_vector for vectors on z-axis --- manimlib/utils/space_ops.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/manimlib/utils/space_ops.py b/manimlib/utils/space_ops.py index 89124d47..c28c4224 100644 --- a/manimlib/utils/space_ops.py +++ b/manimlib/utils/space_ops.py @@ -137,11 +137,14 @@ def z_to_vector(vector): Returns some matrix in SO(3) which takes the z-axis to the (normalized) vector provided as an argument """ - cp = cross(OUT, vector) - if get_norm(cp) == 0: - return np.identity(3) + axis = cross(OUT, vector) + if get_norm(axis) == 0: + if vector[2] > 0: + return np.identity(3) + else: + return rotation_matrix(PI, RIGHT) angle = np.arccos(np.dot(OUT, normalize(vector))) - return rotation_matrix(angle, axis=cp) + return rotation_matrix(angle, axis=axis) def angle_of_vector(vector):