ManimCommunity / manim

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

line.put_start_and_end_on() #3358

Open juanwinograd opened 1 year ago

juanwinograd commented 1 year ago

Description of bug / unexpected behavior

line method put_start_and_end_on(start,end) raises an excpetion when start == end

Expected behavior

I think it should just draw one point

How to reproduce the issue

Code for reproducing the problem ```py line = DashedLine(np.zeros(3),np.zeros(3)) line.put_start_and_end_on(np.zeros(3),np.array([1,0,0])) ```

System specifications

System Details - OS (with version, e.g., Windows 10 v2004 or macOS 10.15 (Catalina)): Windows 10 - RAM: 8GB - Python version (`python/py/python3 --version`): 3.10.8 - Installed modules (provide output from `pip list`): ``` appdirs 1.4.4 asttokens 2.1.0 attrs 18.2.0 backcall 0.2.0 certifi 2022.9.24 charset-normalizer 2.1.1 click 8.1.3 click-default-group 1.2.2 cloup 0.13.1 colorama 0.4.6 colour 0.1.5 commonmark 0.9.1 contourpy 1.0.6 cycler 0.11.0 debugpy 1.6.3 decorator 5.1.1 entrypoints 0.4 et-xmlfile 1.1.0 executing 1.2.0 fonttools 4.38.0 glcontext 2.3.7 idna 3.4 imageio 2.27.0 ipykernel 6.17.1 ipython 8.6.0 isosurfaces 0.1.0 jedi 0.18.2 jupyter_client 7.4.7 jupyter_core 5.0.0 kiwisolver 1.4.4 manim 0.17.2 manim-fonts 0.2.0 ManimPango 0.4.2 mapbox-earcut 1.0.1 matplotlib 3.6.2 matplotlib-inline 0.1.6 matplotlib-label-lines 0.6.0 moderngl 5.7.2 moderngl-window 2.4.2 more-itertools 10.0.0 multipledispatch 0.6.0 nest-asyncio 1.5.6 networkx 2.8.8 numpy 1.23.5 openpyxl 3.0.10 ordered-set 4.1.0 packaging 21.3 pandas 1.5.2 parso 0.8.3 pdflatex 0.1.3 pickleshare 0.7.5 Pillow 9.3.0 pip 23.2.1 platformdirs 2.5.4 prompt-toolkit 3.0.33 psutil 5.9.4 pure-eval 0.2.2 pycairo 1.22.0 pydub 0.25.1 pyglet 2.0.0 Pygments 2.13.0 PyLaTeX 1.4.1 pyparsing 3.0.9 pyrr 0.10.3 python-dateutil 2.8.2 pytz 2022.6 pywin32 305 pyzmq 24.0.1 requests 2.28.1 rich 12.6.0 scipy 1.9.3 screeninfo 0.8.1 setuptools 63.2.0 six 1.16.0 skia-pathops 0.7.4 srt 3.5.2 stack-data 0.6.1 svgelements 1.9.0 tornado 6.2 tqdm 4.64.1 traitlets 5.5.0 typing_extensions 4.5.0 urllib3 1.26.13 watchdog 2.1.9 wcwidth 0.2.5 wheel 0.38.4```
MrDiver commented 1 year ago

Maybe attaching a screenshot would be a good idea!

MrDiver commented 1 year ago
╭───────────────────── Traceback (most recent call last) ──────────────────────╮
│ /usr/local/lib/python3.8/site-packages/manim/cli/render/commands.py:115 in   │
│ render                                                                       │
│                                                                              │
│   112 │   │   │   try:                                                       │
│   113 │   │   │   │   with tempconfig({}):                                   │
│   114 │   │   │   │   │   scene = SceneClass()                               │
│ ❱ 115 │   │   │   │   │   scene.render()                                     │
│   116 │   │   │   except Exception:                                          │
│   117 │   │   │   │   error_console.print_exception()                        │
│   118 │   │   │   │   sys.exit(1)                                            │
│                                                                              │
│ /usr/local/lib/python3.8/site-packages/manim/scene/scene.py:223 in render    │
│                                                                              │
│    220 │   │   """                                                           │
│    221 │   │   self.setup()                                                  │
│    222 │   │   try:                                                          │
│ ❱  223 │   │   │   self.construct()                                          │
│    224 │   │   except EndSceneEarlyException:                                │
│    225 │   │   │   pass                                                      │
│    226 │   │   except RerunSceneException as e:                              │
│                                                                              │
│ /manim/script.py:5 in construct                                              │
│                                                                              │
│   2 class Manimation(Scene):                                                 │
│   3 │   def construct(self):                                                 │
│   4 │     line = DashedLine(np.zeros(3),np.zeros(3))                         │
│ ❱ 5 │     line.put_start_and_end_on(np.zeros(3),np.array([1,0,0]))           │
│   6                                                                          │
│                                                                              │
│ /usr/local/lib/python3.8/site-packages/manim/mobject/geometry/line.py:146 in │
│ put_start_and_end_on                                                         │
│                                                                              │
│    143 │   │   │   self.start = start                                        │
│    144 │   │   │   self.end = end                                            │
│    145 │   │   │   self.generate_points()                                    │
│ ❱  146 │   │   return super().put_start_and_end_on(start, end)               │
│    147 │                                                                     │
│    148 │   def get_vector(self):                                             │
│    149 │   │   return self.get_end() - self.get_start()                      │
│                                                                              │
│ /usr/local/lib/python3.8/site-packages/manim/mobject/mobject.py:1669 in      │
│ put_start_and_end_on                                                         │
│                                                                              │
│   1666 │   │   curr_start, curr_end = self.get_start_and_end()               │
│   1667 │   │   curr_vect = curr_end - curr_start                             │
│   1668 │   │   if np.all(curr_vect == 0):                                    │
│ ❱ 1669 │   │   │   raise Exception("Cannot position endpoints of closed loop │
│   1670 │   │   target_vect = np.array(end) - np.array(start)                 │
│   1671 │   │   axis = (                                                      │
│   1672 │   │   │   normalize(np.cross(curr_vect, target_vect))               │
╰──────────────────────────────────────────────────────────────────────────────╯
Exception: Cannot position endpoints of closed loop
MrDiver commented 1 year ago

I think instead of drawing a point it should draw nothing, because you're trying to convince multiple lines to be in the same singular spot which is not really possible to draw because a line needs a direction.

juanwinograd commented 1 year ago

It's a good option too.

I was drawing a DashedLine from some point to the axes and then updating the line as the point moves. So, both options would work for me. The line should disappear just a moment while the dot cross the axis and reappear in the next frame.