ManimCommunity / manim

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

put_start_and_end_on does not work with Arrow3D #3655

Closed nathanielatom closed 5 months ago

nathanielatom commented 8 months ago

Description of bug / unexpected behavior

In 2D, put_start_and_end_on can be used to animate the tip of an arrow. In 3D the size/volume of the arrow appears to increase without bound, and also rotates much more than expected.

Expected behavior

The same behaviour as 2D but in 3D for an Arrow3D.

How to reproduce the issue

Code for reproducing the problem ```py from manim import * import numpy as np class ArrowAnimation(ThreeDScene): def construct(self): # Define the start and end points start_point = np.array([0, 0, 0]) framerate = 10 # Hz time = np.arange(0, 8, 1/framerate) period = 10 # s end_points = np.array([np.zeros_like(time), np.sin(2 * np.pi * time / period), np.cos(2 * np.pi * time / period)]).T # Create an arrow arrow = Arrow3D(start=start_point, end=end_points[0]) # end_points *= np.linalg.norm(arrow.get_vector()) / np.linalg.norm(arrow.end) # adjust end points so that the tip of the arrow is at the end point arrow.put_start_and_end_on(start_point, end_points[0]) # Create a traced path traced_path = TracedPath(arrow.get_end, stroke_color=ORANGE, stroke_width=2) # Add the arrow and traced path to the scene self.add(arrow, traced_path) # Animate the movement of the arrow for end_point in end_points: self.play( arrow.animate.put_start_and_end_on(start_point, end_point), rate_func=linear, run_time=1/framerate ) self.wait() ```

Additional media files

Images/GIFs https://github.com/ManimCommunity/manim/assets/3137319/7ab8b408-38a6-408b-b1f2-d0e8e7feca5b

Working 2D Version

Code for reproducing the problem ```py from manim import * import numpy as np class ArrowAnimation(Scene): def construct(self): # Define the start and end points start_point = np.array([0, 0, 0]) framerate = 10 # Hz time = np.arange(0, 8, 1/framerate) period = 10 # s end_points = np.array([2 * np.sin(2 * np.pi * time / period), 2 * np.cos(2 * np.pi * time / period), np.zeros_like(time)]).T # Create an arrow arrow = Arrow(start=start_point, end=end_points[0]) # end_points *= np.linalg.norm(arrow.get_vector()) / np.linalg.norm(arrow.end) # adjust end points so that the tip of the arrow is at the end point arrow.put_start_and_end_on(start_point, end_points[0]) # Create a traced path traced_path = TracedPath(arrow.get_end, stroke_color=ORANGE, stroke_width=2) # Add the arrow and traced path to the scene self.add(arrow, traced_path) # Animate the movement of the arrow for end_point in end_points: self.play( arrow.animate.put_start_and_end_on(start_point, end_point), rate_func=linear, run_time=1/framerate ) self.wait() ```

Additional media files

Images/GIFs https://github.com/ManimCommunity/manim/assets/3137319/52e66af5-dfdb-4181-8475-fbc954c54417

System specifications

System Details - OS (with version, e.g., Windows 10 v2004 or macOS 10.15 (Catalina)): - RAM: - Python version (`python/py/python3 --version`): - Installed modules (provide output from `pip list`): ``` - MacOS 13.6.4 (22G513) (Ventura) - RAM: 16 GB - Python 3.9.10 - Pip modules: Package Version Editable project location --------------------------------- ------------------- ------------------------------------------------------------------------- absl-py 1.0.0 aiohttp 3.8.1 aiosignal 1.2.0 alabaster 0.7.12 alembic 1.7.6 altair 4.1.0 annoy 1.17.1 anyio 3.6.2 app-model 0.1.1 appdirs 1.4.4 appnope 0.1.2 APScheduler 3.7.0 argon2-cffi 20.1.0 arms-parser 0.2.4 /Users/Atom/Documents/AEL Backup/Aercoustics/code/arms-parser/source arrow 1.3.0 arviz 0.16.1 asl_bloch_sim 0.0.1 /Users/Atom/Library/CloudStorage/Dropbox/Skule/EECE597/source asteval 0.9.31 astropy 5.3.4 astropy-iers-data 0.2024.2.12.0.31.0 astroquery 0.4.2 asttokens 2.0.5 astunparse 1.6.3 async-generator 1.10 async-lru 2.0.4 async-timeout 4.0.2 attrs 23.2.0 autograd 1.3 autopage 0.5.0 autoray 0.2.5 aws-requests-auth 0.4.2 awscli 1.31.11 Babel 2.14.0 backcall 0.2.0 bcrypt 3.2.0 beautifulsoup4 4.9.3 biocircuits 0.1.5 black 22.1.0 blackjax 0.9.6 bleach 3.3.0 blinker 1.7.0 Bloch-Simulator-Library 2.0 bokeh 3.3.4 boltons 23.0.0 boto3 1.33.11 botocore 1.33.11 Bottleneck 1.3.7 Brotli 1.1.0 build 0.10.0 bump2version 1.0.1 bumpversion 0.5.3 cached-property 1.5.2 cachetools 4.2.4 cachey 0.2.1 canvasapi 3.2.0 certifi 2023.7.22 cffi 1.15.1 cftime 1.6.2 charset-normalizer 3.2.0 click 8.1.7 click-default-group 1.2.4 cliff 3.10.0 clockwork 0.0.1 /Users/Atom/Library/CloudStorage/Dropbox/Sailbot/code/clockwork/source cloudpickle 2.0.0 cloup 2.1.2 cmaes 0.8.2 cmd2 2.3.3 colorama 0.4.3 colorcet 2.0.6 colorio 0.11.2 colorlog 6.6.0 colorspacious 1.1.2 conda 23.7.4 conda-package-handling 2.2.0 conda_package_streaming 0.9.0 confuse 1.4.0 cons 0.4.5 contourpy 1.1.1 convertdate 2.3.2 coverage 5.5 cplot 0.9.3 cryptography 41.0.4 custom-inherit 2.3.1 cycler 0.11.0 Cython 0.29.33 dash 1.20.0 dash-bootstrap-components 0.12.0 dash-colorscales 0.0.4 dash-core-components 1.16.0 dash-daq 0.5.0 dash-html-components 1.1.3 dash-renderer 1.9.1 dash-table 4.11.3 dask 2022.2.0 database-manager 0.2.1 /Users/Atom/Documents/AEL Backup/Aercoustics/code/database-manager/source datashader 0.13.0 datashape 0.5.2 debugpy 1.5.1 decorator 5.1.1 defusedxml 0.6.0 differint 0.3.2 dill 0.3.4 distributed 2022.2.0 dlx 1.0.4 docopt 0.6.2 docplex 2.22.213 docstring-parser 0.13 docutils 0.16 dominate 2.6.0 dtale 1.48.0 easydev 0.12.0 einops 0.4.1 einsteinpy 0.4.0 entrypoints 0.3 eqtk 0.1.1 et-xmlfile 1.0.1 etuples 0.3.8 event-processing 0.3.2 /Users/Atom/Documents/AEL Backup/Aercoustics/code/event-processing/source exceptiongroup 1.0.0rc9 executing 0.8.2 FALCONN 1.3.1 fancycompleter 0.9.1 fastdtw 0.3.4 fastjsonschema 2.15.1 fastprogress 1.0.3 fCWT 0.1.17 filelock 3.9.0 Flask 2.1.3 Flask-Compress 1.9.0 flask-ngrok 0.0.25 flatbuffers 2.0 fonttools 4.42.1 fqdn 1.5.1 freetype-py 2.2.0 frozenlist 1.3.1 fsspec 2022.1.0 future 0.18.2 gast 0.5.3 githubdl 0.1.6 glcontext 2.5.0 gmpy2 2.1.2 google-api-core 2.11.0 google-api-python-client 2.82.0 google-auth 2.16.2 google-auth-httplib2 0.1.0 google-auth-oauthlib 0.4.6 google-pasta 0.2.0 googleapis-common-protos 1.59.0 googledrivedownloader 0.4 graphviz 0.16 greenlet 1.1.2 grpcio 1.43.0 h11 0.14.0 h5netcdf 1.1.0 h5py 3.2.1 HeapDict 1.0.1 hijri-converter 2.1.2 holidays 0.11.1 hsluv 5.0.2 html5lib 1.1 htmlmin 0.1.12 httplib2 0.22.0 humanize 3.2.0 ibroadcast 1.1.2.dev0 idna 3.4 ImageHash 4.2.0 imageio 2.12.0 imagesize 1.4.1 importlib-metadata 4.10.1 importlib-resources 6.1.0 in-n-out 0.1.6 inflection 0.5.1 influxdb 5.3.1 iniconfig 1.1.1 ipdb 0.13.13 ipykernel 6.9.1 ipympl 0.9.2 ipython 8.15.0 ipython-genutils 0.2.0 ipywidgets 8.0.4 iso8601 1.0.2 isodate 0.6.1 isoduration 20.11.0 isosurfaces 0.1.0 itsdangerous 2.1.2 jax 0.4.4 jaxlib 0.4.4 jaxopt 0.6 jdcal 1.4.1 jedi 0.17.2 Jinja2 3.1.2 jmespath 0.10.0 joblib 1.2.0 jplephem 2.15 json5 0.9.5 jsonpatch 1.33 jsonpickle 3.0.2 jsonpointer 2.1 jsonschema 4.20.0 jsonschema-specifications 2023.12.1 jupyter 1.0.0 jupyter-bokeh 3.0.7 jupyter_client 7.4.8 jupyter-console 6.2.0 jupyter-contrib-core 0.3.3 jupyter-contrib-nbextensions 0.5.1 jupyter_core 5.1.2 jupyter-events 0.9.0 jupyter-highlight-selected-word 0.2.0 jupyter-latex-envs 1.4.6 jupyter-lsp 2.2.1 jupyter-nbextensions-configurator 0.6.1 jupyter-packaging 0.7.12 jupyter_server 2.12.4 jupyter_server_terminals 0.5.1 jupyter-tabnine 1.2.2 jupyterlab 4.0.10 jupyterlab-pygments 0.1.2 jupyterlab_server 2.25.2 jupyterlab-widgets 3.0.5 kaleido 0.2.1 keras 2.8.0 Keras-Preprocessing 1.1.2 keyring 23.0.1 kiwisolver 1.4.5 korean-lunar-calendar 0.2.1 lcapy 0.98 lckr-jupyterlab-variableinspector 3.0.9 libclang 13.0.0 llvmlite 0.41.0 lmfit 1.2.2 locket 0.2.1 logical-unification 0.4.5 lxml 4.6.3 lz4 3.1.3 m2r2 0.2.7 m3u8 2.0.0 magicgui 0.4.0 Mako 1.1.6 manim 0.18.0 ManimPango 0.5.0 mapbox-earcut 1.0.1 Markdown 3.3.6 markdown-it-py 2.1.0 MarkupSafe 2.1.1 matplotlib 3.8.2 matplotlib-inline 0.1.6 matplotx 0.3.10 mdurl 0.1.2 memory-profiler 0.58.0 meshio 4.4.6 mimeparse 0.1.3 miniKanren 1.0.3 missingno 0.4.2 mistune 2.0.4 mkl-service 2.4.0 mock 5.1.0 moderngl 5.10.0 moderngl-window 2.4.4 monai 0.8.1 more-itertools 8.10.0 mpmath 1.3.0 msgpack 1.0.2 multidict 6.0.2 multipledispatch 0.6.0 multiprocess 0.70.12.2 multitasking 0.0.9 munkres 1.1.4 mutagen 1.46.0 mypy-extensions 0.4.3 napari 0.4.17 napari-console 0.0.7 napari-plugin-engine 0.2.0 napari-svg 0.1.6 natsort 7.1.1 nbclassic 0.4.8 nbclient 0.5.2 nbconvert 7.2.7 nbformat 5.7.1 nest-asyncio 1.5.6 netCDF4 1.6.1 networkx 3.2.1 ngt 2.0.4 nibabel 3.2.2 nilearn 0.9.0 nmslib 2.1.1 notebook 6.5.2 notebook_shim 0.2.2 npe2 0.6.2 npTDMS 0.18.1 npx 0.1.0 ntlm-auth 1.5.0 numba 0.58.1 numdifftools 0.9.41 numexpr 2.8.7 numpy 1.26.4 numpydoc 1.5.0 numpyro 0.11.0 nvflare 2.0.19 nvm-tools 0.5.9 /Users/Atom/Documents/AEL Backup/Aercoustics/code/nvm-tools/source oauthlib 3.2.0 objgraph 3.5.0 opencv-python 4.5.4.60 openpyxl 3.0.7 opt-einsum 3.3.0 optuna 2.10.0 outcome 1.3.0.post0 overrides 7.4.0 packaging 23.2 pandas 2.2.1 pandas-profiling 2.11.0 pandocfilters 1.4.3 param 1.12.0 paramiko 2.7.2 parse 1.19.0 parso 0.7.1 partd 1.2.0 path-and-address 2.0.1 pathspec 0.9.0 patsy 0.5.1 pbr 5.5.1 PennyLane 0.18.0 PennyLane-Lightning 0.18.0 pexpect 4.8.0 pgmpy 0.1.22 phik 0.11.2 pickleshare 0.7.5 Pillow 9.4.0 Pint 0.18 pip 24.0 platformdirs 2.6.2 plotly 5.18.0 pluggy 1.3.0 ply 3.11 polars 0.20.15 poliastro 0.17.0 pooch 1.6.0 ppscore 1.3.0 prettytable 3.0.0 profimp 0.1.0 prometheus-client 0.9.0 prompt-toolkit 3.0.36 protobuf 4.22.1 pscript 0.7.7 psrecord 1.2 psutil 5.8.0 psygnal 0.7.0 ptyprocess 0.7.0 pure-eval 0.2.2 pvlib 0.9.5 py 1.10.0 pyarrow 15.0.1 pyasn1 0.4.8 pyasn1-modules 0.2.8 pybind11 2.6.1 pycairo 1.25.1 pycosat 0.6.4 pycparser 2.21 pycryptodomex 3.16.0 pyct 0.4.8 pydantic 1.9.0 pydicom 2.4.4 pydub 0.25.1 pyee 7.0.4 pyerfa 2.0.0.1 pyglet 2.0.10 Pygments 2.14.0 pymc 5.0.2 PyMeeus 0.5.11 PyNaCl 1.4.0 pynufft 2022.1.1 pyobjc-core 10.1 pyobjc-framework-Cocoa 10.1 PyOpenGL 3.1.6 pyOpenSSL 23.2.0 pyparsing 3.1.1 pyperclip 1.8.2 pypng 0.0.21 pyppeteer 0.2.2 pyproject_hooks 1.0.0 PyQt5 5.15.7 PyQt5-Qt5 5.15.2 PyQt5-sip 12.11.0 pyqtgraph 0.13.1 pyquist 0.8.15 /Users/Atom/Documents/AEL Backup/Aercoustics/code/pyquist/source pyrepl 0.9.0 pyro-api 0.1.2 pyro-ppl 1.8.0 pyrr 0.10.3 pyrsistent 0.17.3 PySocks 1.7.1 pytensor 2.9.1 pytest 8.0.0 pytest-base-url 1.4.2 pytest-cov 2.11.1 pytest-html 3.1.1 pytest-metadata 1.11.0 pytest-variables 1.9.0 python-constraint 1.4.0 python-dateutil 2.8.2 python-json-logger 2.0.7 python-jsonrpc-server 0.4.0 python-language-server 0.36.2 python-minifier 2.5.0 pytomlpp 1.0.10 pytz 2021.1 pyusb 1.2.1 pyvo 1.1 PyWavelets 1.3.0 PyYAML 6.0.1 pyzmq 24.0.1 qiskit 0.31.0 qiskit-aer 0.9.1 qiskit-aqua 0.9.5 qiskit-ibmq-provider 0.17.0 qiskit-ignis 0.6.0 qiskit-terra 0.18.3 qtconsole 5.0.2 QtPy 2.3.0 Quandl 3.6.1 qutip 4.6.2 rdflib 6.1.1 referencing 0.32.1 report-manager 0.4.0 /Users/Atom/Documents/AEL Backup/Aercoustics/code/report-manager/source requests 2.31.0 requests-ntlm 1.1.0 requests-oauthlib 1.3.1 retry 0.9.2 retrying 1.3.3 retworkx 0.10.2 rfc3339-validator 0.1.4 rfc3986-validator 0.1.1 rich 13.3.1 rise 5.7.1 rpds-py 0.17.1 rpy2 3.5.10 rsa 4.5 ruamel.yaml 0.17.32 ruamel.yaml.clib 0.2.2 s3transfer 0.8.2 scikit-image 0.19.3 scikit-learn 1.2.1 scipy 1.12.0 screeninfo 0.8.1 seaborn 0.11.1 selenium 4.17.2 self-attention-cv 1.2.3 semantic-version 2.6.0 Send2Trash 1.8.2 setuptools 68.2.2 sfepy 2022.1 sgp4 2.19 sigpy 0.1.23 SimpleITK 2.1.1 six 1.16.0 skia-pathops 0.7.4 sklearn 0.0 skyfield 1.39 snakeviz 2.1.0 sniffio 1.3.0 snowballstemmer 2.1.0 sortedcontainers 2.4.0 sounddevice 0.4.5 soupsieve 2.2.1 spectrum 0.8.1 speedtest-cli 2.1.3 Sphinx 4.5.0 sphinx-codeautolink 0.3.0 sphinx-rtd-theme 0.5.1 sphinxcontrib-applehelp 1.0.2 sphinxcontrib-devhelp 1.0.2 sphinxcontrib-htmlhelp 2.0.0 sphinxcontrib-jsmath 1.0.1 sphinxcontrib-qthelp 1.0.3 sphinxcontrib-serializinghtml 1.1.5 SQLAlchemy 1.4.31 squarify 0.4.3 srt 3.5.3 stack-data 0.1.4 statsmodels 0.12.2 stevedore 3.5.0 strsimpy 0.2.0 superqt 0.3.1 svgelements 1.9.6 sycomore 1.3.2 symengine 0.8.1 sympy 1.12 tables 3.7.0 tangled-up-in-unicode 0.0.7 tblib 1.7.0 tenacity 6.3.1 tensorboard 2.8.0 tensorboard-data-server 0.6.1 tensorboard-plugin-wit 1.8.1 tensorboardX 2.5 tensorflow 2.8.0 tensorflow-io-gcs-filesystem 0.24.0 termcolor 1.1.0 terminado 0.9.2 testpath 0.4.4 tf-estimator-nightly 2.8.0.dev2021122109 Theano 1.0.5 threadpoolctl 2.1.0 tifffile 2021.11.2 tinycss2 1.2.1 toml 0.10.2 tomli 2.0.0 tonality 0.6.9 /Users/Atom/Documents/AEL Backup/Aercoustics/code/tonality/source toolz 0.11.1 torch 1.11.0 torch-cluster 1.5.9 torch-geometric 2.0.3 torch-scatter 2.0.9 torch-sparse 0.6.12 torch-spline-conv 1.2.1 torchaudio 0.11.0 torchvision 0.12.0 tornado 6.2 tqdm 4.64.0 traitlets 5.8.0 trio 0.24.0 trio-websocket 0.11.1 turbine-parser 1.0.1 /Users/Atom/Documents/AEL Backup/Aercoustics/code/turbine-parser/source tweedledum 1.1.1 typer 0.4.1 types-python-dateutil 2.8.19.20240106 typing_extensions 4.9.0 tzdata 2023.3 tzlocal 2.1 ujson 4.0.2 uncertainties 3.1.7 unicode 2.9 unicodedata2 15.1.0 uri-template 1.3.0 uritemplate 4.1.1 urllib3 1.26.5 utm 0.7.0 visions 0.6.0 vispy 0.11.0 vtk 9.1.0 watchdog 3.0.0 wcwidth 0.2.5 webcolors 1.13 webencodings 0.5.1 websocket-client 1.2.1 websockets 8.1 Werkzeug 2.0.3 wheel 0.41.2 widgetsnbextension 4.0.5 wmctrl 0.3 wrapt 1.13.3 wslink 1.6.6 wsproto 1.2.0 xarray 2023.2.0 xarray-einstats 0.5.1 xdot 1.2 xlrd 2.0.1 XlsxWriter 1.3.8 xmltodict 0.12.0 xyzservices 2022.9.0 yacs 0.1.8 yarl 1.8.1 yfinance 0.1.64 youtube-dl 2021.12.17 yt-dlp 2023.2.17 zict 2.0.0 zipp 3.17.0 zstandard 0.21.0 ```
FFMPEG Output of `ffmpeg -version`: ``` ffmpeg version 6.1 Copyright (c) 2000-2023 the FFmpeg developers built with Apple clang version 15.0.0 (clang-1500.1.0.2.5) configuration: --prefix=/usr/local/Cellar/ffmpeg/6.1-with-options_3 --enable-shared --cc=clang --host-cflags= --host-ldflags='-Wl,-ld_classic' --enable-gpl --enable-libaom --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-demuxer=dash --enable-opencl --enable-audiotoolbox --enable-videotoolbox --disable-htmlpages --enable-libtesseract --enable-libxvid --enable-libzimg libavutil 58. 29.100 / 58. 29.100 libavcodec 60. 31.102 / 60. 31.102 libavformat 60. 16.100 / 60. 16.100 libavdevice 60. 3.100 / 60. 3.100 libavfilter 9. 12.100 / 9. 12.100 libswscale 7. 5.100 / 7. 5.100 libswresample 4. 12.100 / 4. 12.100 libpostproc 57. 3.100 / 57. 3.100 ```

Additional comments

Even in 2D the put_start_and_end_on() method seems to use the line/vector (and ignores the triangle/cone) for the end point, whereas when initializing the Arrow class the end point does represent the tip of the triangle/cone.

camburd2 commented 8 months ago

I will look into this.

SirJamesClarkMaxwell commented 7 months ago

good knew I have found a solution!!

nathanielatom commented 7 months ago

Care to elaborate?

SirJamesClarkMaxwell commented 7 months ago

Tommorow I will create a PR. The problem was in scaling. I had to add a get_start and get_end methods for cone and arrow3d classes.

SirJamesClarkMaxwell commented 7 months ago

Screenshot_20240416_012316_Discord.jpg

This is the code I have added

nathanielatom commented 7 months ago

Cool thank you! I tried out the PR and it works beautifully.