ManimCommunity / ManimCommunity/manim

LinearTransformationScene in v0.17.3: self.add_vector() breaks fixed objects

Open
#3,349 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
40.9k
Forks
3.1k
Avg merge
3d 12h
Merged PRs (30d)
25

Description

## Description of bug / unexpected behavior
When using `self.add_vector()` to add a vector to a `LinearTransformationScene()` all mobjects on the scene become transformable mobjects.

See also [https://discord.com/channels/581738731934056449/1146895377841262725/1146895377841262725](https://discord.com/channels/581738731934056449/1146895377841262725/1146895377841262725)

## Expected behavior
Adding a vector should not change the behavior of other objects

## How to reproduce the issue
In `LinearTransformationSceneExample_01` an arrow is added using `self.add_vector()`, which results in also the `title` and `matrix_tex` being affected by the matrix operation. In `LinearTransformationSceneExample_02` the same arrow is manually added using `self.add_transformable_mobject()` and the other objects stay unaffected.

Code for reproducing the problem

```python
class LinearTransformationSceneExample_01(LinearTransformationScene):
def __init__(self):
LinearTransformationScene.__init__(
self,
show_coordinates=True,
leave_ghost_vectors=True,
)

def construct(self):
matrix = [[1/2, 0], [0, -1/2]]
matrix_tex = MathTex(r"\hat{S}_z = \begin{bmatrix} \frac{1}{2}\hbar & 0 \\ "
r"0 & -\frac{1}{2}\hbar \end{bmatrix}").to_edge(UL).add_background_rectangle()
self.add_foreground_mobject(matrix_tex)

self.add_vector([0.7071, 0.7071], color=BLUE)

self.add_title("Hello")
self.apply_matrix(matrix)
self.wait()
```
```python
class LinearTransformationSceneExample_02(LinearTransformationScene):
def __init__(self):
LinearTransformationScene.__init__(
self,
show_coordinates=True,
leave_ghost_vectors=True,
)

def construct(self):
matrix = [[1/2, 0], [0, -1/2]]
matrix_tex = MathTex(r"\hat{S}_z = \begin{bmatrix} \frac{1}{2}\hbar & 0 \\ "
r"0 & -\frac{1}{2}\hbar \end{bmatrix}").to_edge(UL).add_background_rectangle()
self.add_foreground_mobject(matrix_tex)

self.add_transformable_mobject(Vector([0.7071, 0.7071], color=BLUE))

self.add_title("Hello")
self.apply_matrix(matrix)
self.wait()
```

## Additional media files

Images/GIFs

`LinearTransformationSceneExample_01`
https://github.com/ManimCommunity/manim/assets/8582807/2db3067c-bd80-4892-ac49-4cf4af90123b

`LinearTransformationSceneExample_02`
https://github.com/ManimCommunity/manim/assets/8582807/c68d15a2-1b3d-4980-9856-e42db47fc2bf

## System specifications

System Details
- ManimCE v0.17.3 on Manimator/Discord and Windows 10

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with LinearTransformationScene's add_vector and compare it with add_transformable_mobject, then trace how apply_matrix selects objects for transformation. Reproduce both LinearTransformationSceneExample cases and confirm that adding a vector leaves the title and matrix_tex unaffected while the vector is transformed.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
computer-graphics
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.