Closed as duplicate of#2412
Description
Description of bug / unexpected behavior
When trying to rotate an Image() around an axis in the XY-plane the image is also rotated around the Z-axis and thus cannot be mirrored.
Expected behavior
When rotating a 2D-object 180° around an axis in the XY-plane it should end up mirrored on the scene.
How to reproduce the issue
A follow up from the discussion on Discord
https://discord.com/channels/581738731934056449/1027662457130455081
Code for reproducing the problem
import requests
import io
from PIL import Image
class TestScene(Scene):
def construct(self):
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}
response = requests.get("https://raw.githubusercontent.com/ManimCommunity/manim/main/logo/cropped.png", headers=headers)
image_bytes = io.BytesIO(response.content)
image = Image.open(image_bytes)
def reflect_across(self, line, **kwargs):
A = line.get_start()
B = line.get_end()
AB = B - A
P = self.get_center()
AP = P - A
BP = P - B
perp_to_AB = AP - AB*(np.dot(AP, AB))/(np.linalg.norm(AB)**2)
self.flip(AB).shift(-2*perp_to_AB)
return self
# This binds the defined function reflect_across to the mobject class as if it were a native manim mobject method
# This isn't necessary but it does allow the function to be used like any established mobject method, such as rotate, shift, etc.
setattr(Mobject, "reflect_across", reflect_across)
flipflop = ImageMobject(image)
rect = SurroundingRectangle(flipflop)
line = Line(3*DL, 2*UP + 2*LEFT)
self.add(flipflop, rect, line)
self.wait()
self.play(flipflop.animate.reflect_across(line), rect.animate.reflect_across(line), run_time = 3)
self.wait()
self.play(flipflop.animate.reflect_across(line), rect.animate.reflect_across(line), run_time = 3)
self.wait()
self.play(flipflop.animate.reflect_across(line), rect.animate.reflect_across(line), run_time = 3)
Additional media files
Images/GIFs
see here:
https://discord.com/channels/581738731934056449/1027662457130455081/1028225119857950720
System specifications
System Details
- OS Windows 10
- RAM: enough
- Python 3.9.8
- Manim Community v0.16.0.post0
LaTeX details
- LaTeX distribution (e.g. TeX Live 2020):
- Installed LaTeX packages:
FFMPEG
Output of ffmpeg -version
:
ffmpeg version 4.2.3 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 9.3.1 (GCC) 20200523
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
libavutil 56. 31.100 / 56. 31.100
libavcodec 58. 54.100 / 58. 54.100
libavformat 58. 29.100 / 58. 29.100
libavdevice 58. 8.100 / 58. 8.100
libavfilter 7. 57.100 / 7. 57.100
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Status
🆕 New