ManimCommunity / manim

A community-maintained Python framework for creating mathematical animations.
https://www.manim.community
MIT License
26.48k stars 1.82k forks source link

Uhhh... help? #3898

Closed WiktorProj closed 3 months ago

WiktorProj commented 3 months ago

Description of bug / unexpected behavior

I don't even know how i got here!

Expected behavior

Should generate a vector field

How to reproduce the issue

Add a 1/ to the lambda

Code for reproducing the problem ```py class BasicUsage(Scene): def construct(self): func = lambda pos: 1/pos[0]*RIGHT + 1/pos[1]*UP self.add(ArrowVectorField(func)) ```

Logs

Terminal output Exception Traceback (most recent call last) Cell In[8], line 9 4 self.add(ArrowVectorField(func)) 8 # don't remove below command for run button to work ----> 9 get_ipython().run_line_magic('manim', '-qm -v DEBUG BasicUsage') File /usr/local/lib/python3.11/site-packages/IPython/core/interactiveshell.py:2480, in InteractiveShell.run_line_magic(self, magic_name, line, _stack_depth) 2478 kwargs['local_ns'] = self.get_local_scope(stack_depth) 2479 with self.builtin_trap: -> 2480 result = fn(*args, **kwargs) 2482 # The code below prevents the output from being displayed 2483 # when using magics with decorator @output_can_be_silenced 2484 # when the last Python token in the expression is a ';'. 2485 if getattr(fn, magic.MAGIC_OUTPUT_CAN_BE_SILENCED, False): File /usr/local/lib/python3.11/site-packages/manim/utils/ipython_magic.py:143, in ManimMagic.manim(self, line, cell, local_ns) 141 SceneClass = local_ns[config["scene_names"][0]] 142 scene = SceneClass(renderer=renderer) --> 143 scene.render() 144 finally: 145 # Shader cache becomes invalid as the context is destroyed 146 shader_program_cache.clear() File /usr/local/lib/python3.11/site-packages/manim/scene/scene.py:229, in Scene.render(self, preview) 227 self.setup() 228 try: --> 229 self.construct() 230 except EndSceneEarlyException: 231 pass Cell In[8], line 4, in BasicUsage.construct(self) 2 def construct(self): 3 func = lambda pos: 1/pos[0]*RIGHT + 1/pos[1]*UP ----> 4 self.add(ArrowVectorField(func)) File /usr/local/lib/python3.11/site-packages/manim/mobject/vector_field.py:604, in ArrowVectorField.__init__(self, func, color, color_scheme, min_color_scheme_value, max_color_scheme_value, colors, x_range, y_range, z_range, three_dimensions, length_func, opacity, vector_config, **kwargs) 601 y_range = np.arange(*self.y_range) 602 z_range = np.arange(*self.z_range) 603 self.add( --> 604 *[ 605 self.get_vector(x * RIGHT + y * UP + z * OUT) 606 for x, y, z in it.product(x_range, y_range, z_range) 607 ] 608 ) 609 self.set_opacity(self.opacity) File /usr/local/lib/python3.11/site-packages/manim/mobject/vector_field.py:605, in (.0) 601 y_range = np.arange(*self.y_range) 602 z_range = np.arange(*self.z_range) 603 self.add( 604 *[ --> 605 self.get_vector(x * RIGHT + y * UP + z * OUT) 606 for x, y, z in it.product(x_range, y_range, z_range) 607 ] 608 ) 609 self.set_opacity(self.opacity) File /usr/local/lib/python3.11/site-packages/manim/mobject/vector_field.py:628, in ArrowVectorField.get_vector(self, point) 626 if norm != 0: 627 output *= self.length_func(norm) / norm --> 628 vect = Vector(output, **self.vector_config) 629 vect.shift(point) 630 if self.single_color: File /usr/local/lib/python3.11/site-packages/manim/mobject/geometry/line.py:670, in Vector.__init__(self, direction, buff, **kwargs) 667 if len(direction) == 2: 668 direction = np.hstack([direction, 0]) --> 670 super().__init__(ORIGIN, direction, buff=buff, **kwargs) File /usr/local/lib/python3.11/site-packages/manim/mobject/geometry/line.py:530, in Arrow.__init__(self, stroke_width, buff, max_tip_length_to_length_ratio, max_stroke_width_to_length_ratio, *args, **kwargs) 527 # TODO, should this be affected when 528 # Arrow.set_stroke is called? 529 self.initial_stroke_width = self.stroke_width --> 530 self.add_tip(tip_shape=tip_shape) 531 self._set_stroke_width_from_length() File /usr/local/lib/python3.11/site-packages/manim/mobject/geometry/arc.py:121, in TipableVMobject.add_tip(self, tip, tip_shape, tip_length, tip_width, at_start) 119 else: 120 self.position_tip(tip, at_start) --> 121 self.reset_endpoints_based_on_tip(tip, at_start) 122 self.asign_tip_attr(tip, at_start) 123 self.add(tip) File /usr/local/lib/python3.11/site-packages/manim/mobject/geometry/arc.py:204, in TipableVMobject.reset_endpoints_based_on_tip(self, tip, at_start) 202 self.put_start_and_end_on(tip.base, self.get_end()) 203 else: --> 204 self.put_start_and_end_on(self.get_start(), tip.base) 205 return self File /usr/local/lib/python3.11/site-packages/manim/mobject/geometry/tips.py:133, in ArrowTip.base(self) 117 @property 118 def base(self) -> Point3D: 119 r"""The base point of the arrow tip. 120 121 This is the point connecting to the arrow line. (...) 131 132 """ --> 133 return self.point_from_proportion(0.5) File /usr/local/lib/python3.11/site-packages/manim/mobject/types/vectorized_mobject.py:1451, in VMobject.point_from_proportion(self, alpha) 1448 return curve(residue) 1450 current_length += length -> 1451 raise Exception( 1452 "Not sure how you reached here, please file a bug report at https://github.com/ManimCommunity/manim/issues/new/choose" 1453 ) Exception: Not sure how you reached here, please file a bug report at https://github.com/ManimCommunity/manim/issues/new/choose
uwezi commented 3 months ago

I assume that you are aware of the fact that you are trying to divide by zero along the axis-lines? This would make the resulting vectors infinitely long - which is a bit difficult to handle...

class BasicUsage(Scene):
    def construct(self):
        def func(pos):
            if pos[0] != 0 and pos[1] != 0:
                return 1/pos[0]*RIGHT + 1/pos[1]*UP
            else:
                return ORIGIN
        self.add(ArrowVectorField(func))

image