Skip to content

Commit 7941e18

Browse files
MrDiverpre-commit-ci[bot]noamzaksbehackl
authored
enhancement(vector_field): added fit_to_coordinate_system (#2728)
* enhancement(vector_field): added fit_to_coordinate_system * tmp(vector_field) decision stage for implementation * Update vector_field.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix OpenGL segfaulting when running self.play or self.wait (#2734) * make play run only on main thread * prefer dict.update Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Noam Zaks <[email protected]> Co-authored-by: Benjamin Hackl <[email protected]>
1 parent 083ffe0 commit 7941e18

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

manim/mobject/vector_field.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
from manim.animation.updaters.update import UpdateFromAlphaFunc
2121
from manim.mobject.geometry.line import Vector
22+
from manim.mobject.graphing.coordinate_systems import CoordinateSystem
2223
from manim.mobject.opengl.opengl_vectorized_mobject import OpenGLVMobject
2324

2425
from .. import config
@@ -168,6 +169,22 @@ def construct(self):
168169
"""
169170
return lambda p: func(p * scalar)
170171

172+
def fit_to_coordinate_system(self, coordinate_system: CoordinateSystem):
173+
"""Scale the vector field to fit a coordinate system.
174+
175+
This method is useful when the vector field is defined in a coordinate system
176+
different from the one used to display the vector field.
177+
178+
This method can only be used once because it transforms the origin of each vector.
179+
180+
Parameters
181+
----------
182+
coordinate_system
183+
The coordinate system to fit the vector field to.
184+
185+
"""
186+
self.apply_function(lambda pos: coordinate_system.coords_to_point(*pos))
187+
171188
def nudge(
172189
self,
173190
mob: Mobject,

0 commit comments

Comments
 (0)