A community-maintained Python framework for creating mathematical animations.
Fixed :class:`~.ThreeDAxes` axis shift bug. (#2276)
Alex Lembcke177c31027f11
diff --git a/manim/mobject/coordinate_systems.py b/manim/mobject/coordinate_systems.pyindex 8bb52f610..03a6ec11f 100644--- a/manim/mobject/coordinate_systems.py+++ b/manim/mobject/coordinate_systems.py@@ -2183,11 +2183,16 @@ class ThreeDAxes(Axes):z_axis = self._create_axis(self.z_range, self.z_axis_config, self.z_length)- z_axis.rotate_about_zero(-PI / 2, UP)- z_axis.rotate_about_zero(angle_of_vector(self.z_normal))+ # [ax.x_min, ax.x_max] used to account for LogBase() scaling+ # where ax.x_range[0] != ax.x_min+ z_origin = self._origin_shift([z_axis.x_min, z_axis.x_max])++ z_axis.rotate_about_number(z_origin, -PI / 2, UP)+ z_axis.rotate_about_number(z_origin, angle_of_vector(self.z_normal))+ z_axis.shift(-z_axis.number_to_point(z_origin))z_axis.shift(self.x_axis.number_to_point(- self._origin_shift([z_axis.x_min, z_axis.x_max]),+ self._origin_shift([self.x_axis.x_min, self.x_axis.x_max]),),)diff --git a/tests/test_axes_shift.py b/tests/test_axes_shift.pyindex bd9956622..d3735492b 100644--- a/tests/test_axes_shift.py+++ b/tests/test_axes_shift.py@@ -1,10 +1,56 @@import numpy as npimport pytest-from manim.mobject.coordinate_systems import Axes+from manim.mobject.coordinate_systems import Axes, ThreeDAxes+from manim.utils.scale import LogBasedef test_axes_origin_shift():ax = Axes(x_range=(5, 10, 1), y_range=(40, 45, 0.5))assert np.allclose(ax.coords_to_point(5, 40), ax.x_axis.number_to_point(5))assert np.allclose(ax.coords_to_point(5, 40), ax.y_axis.number_to_point(40))+++def test_axes_origin_shift_logbase():+ ax = Axes(+ x_range=(5, 10, 1),+ y_range=(3, 8, 1),+ x_axis_config={"scaling": LogBase()},+ y_axis_config={"scaling": LogBase()},+ )+ assert np.allclose(+ ax.coords_to_point(10 ** 5, 10 ** 3), ax.x_axis.number_to_point(10 ** 5)+ )+ assert np.allclose(+ ax.coords_to_point(10 ** 5, 10 ** 3), ax.y_axis.number_to_point(10 ** 3)+ )+++def test_3daxes_origin_shift():+ ax = ThreeDAxes(x_range=(3, 9, 1), y_range=(6, 12, 1), z_range=(-1, 1, 0.5))+ assert np.allclose(ax.coords_to_point(3, 6, 0), ax.x_axis.number_to_point(3))+ assert np.allclose(ax.coords_to_point(3, 6, 0), ax.y_axis.number_to_point(6))+ assert np.allclose(ax.coords_to_point(3, 6, 0), ax.z_axis.number_to_point(0))+++def test_3daxes_origin_shift_logbase():+ ax = ThreeDAxes(+ x_range=(3, 9, 1),+ y_range=(6, 12, 1),+ z_range=(2, 5, 1),+ x_axis_config={"scaling": LogBase()},+ y_axis_config={"scaling": LogBase()},+ z_axis_config={"scaling": LogBase()},+ )+ assert np.allclose(+ ax.coords_to_point(10 ** 3, 10 ** 6, 10 ** 2),+ ax.x_axis.number_to_point(10 ** 3),+ )+ assert np.allclose(+ ax.coords_to_point(10 ** 3, 10 ** 6, 10 ** 2),+ ax.y_axis.number_to_point(10 ** 6),+ )+ assert np.allclose(+ ax.coords_to_point(10 ** 3, 10 ** 6, 10 ** 2),+ ax.z_axis.number_to_point(10 ** 2),+ )