Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image-mobject not rotating correctly around in-plane axis #2979

Open
Tracked by #3482
uwezi opened this issue Oct 8, 2022 · 1 comment
Open
Tracked by #3482

Image-mobject not rotating correctly around in-plane axis #2979

uwezi opened this issue Oct 8, 2022 · 1 comment

Comments

@uwezi
Copy link
Contributor

uwezi commented Oct 8, 2022

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
@MrDiver MrDiver added this to Dev Board Nov 8, 2022
@MrDiver MrDiver moved this to 🆕 New in Dev Board Nov 8, 2022
@uwezi
Copy link
Contributor Author

uwezi commented Dec 16, 2022

This issue is still open in v0.17.1

TestScene.mp4

@MrDiver MrDiver mentioned this issue Dec 2, 2023
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🆕 New
Development

No branches or pull requests

1 participant