Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Moved axis shifting logic to origin_shift

Alex Lembcke98441eb56614
diff --git a/manim/mobject/coordinate_systems.py b/manim/mobject/coordinate_systems.py
index a84df4dc8..b7448c95c 100644
--- a/manim/mobject/coordinate_systems.py
+++ b/manim/mobject/coordinate_systems.py
@@ -246,24 +246,13 @@ class Axes(VGroup, CoordinateSystem):
new_config["length"] = length
axis = NumberLine(range_terms, **new_config)
- # without the if/elif, graph does not exist when min > 0 or max < 0
+ # without the call to origin_shift, graph does not exist when min > 0 or max < 0
# shifts the axis so that 0 is centered
- if range_terms[0] > 0:
- axis.shift(-axis.number_to_point(range_terms[0]))
- elif range_terms[1] < 0:
- axis.shift(-axis.number_to_point(range_terms[1]))
- else:
- axis.shift(-axis.number_to_point(0))
+ axis.shift(-axis.number_to_point(self.origin_shift(range_terms)))
return axis
def coords_to_point(self, *coords):
- if self.x_range[0] > 0:
- x_origin = self.x_range[0]
- elif self.x_range[1] < 0:
- x_origin = self.x_range[1]
- else:
- x_origin = 0
- origin = self.x_axis.number_to_point(x_origin)
+ origin = self.x_axis.number_to_point(self.origin_shift(self.x_range))
result = np.array(origin)
for axis, coord in zip(self.get_axes(), coords):
result += axis.number_to_point(coord) - origin
@@ -373,6 +362,21 @@ class Axes(VGroup, CoordinateSystem):
return line_graph
+ def origin_shift(self, axis_range):
+ """Shifts graph mobjects to compensate when 0 is not on the axis.
+
+ Parameters
+ ----------
+ axis_range : Union[:class:`list`, :class:`numpy.ndarray`]
+ The range of the axis : `(x_min, x_max, x_step)`.
+ """
+ if axis_range[0] > 0:
+ return axis_range[0]
+ if axis_range[1] < 0:
+ return axis_range[1]
+ else:
+ return 0
+
class ThreeDAxes(Axes):
"""A 3-dimensional set of axes.
@@ -450,12 +454,7 @@ 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))
- if x_range[0] > 0:
- z_axis.shift(self.x_axis.n2p(x_range[0]))
- elif x_range[1] < 0:
- z_axis.shift(self.x_axis.n2p(x_range[1]))
- else:
- z_axis.shift(self.x_axis.n2p(0))
+ z_axis.shift(self.x_axis.number_to_point(self.origin_shift(x_range)))
self.axes.add(z_axis)
self.add(z_axis)