matheart / manim-physics Goto Github PK
View Code? Open in Web Editor NEWPhysics simulation plugin of Manim that can generate scenes in various branches of Physics.
Physics simulation plugin of Manim that can generate scenes in various branches of Physics.
As the name says, a Class that can start a random walk for any Mobject that it receives.
Similar to this one:
https://www.youtube.com/watch?v=4c4lVjHGRjU
Hello everyone, this is my first time using manim, manim-physics and GitHub, i hope that i'm doing every fine and respecting all the rules,
So my issue is that i want to create an animation of a magnetic field streamline being blocked by a metallic shield, and as a starter i wanted to try the code provided in the doc, but when i try to input the Wire example in my visual studio i get this message error :
"Wire" is not defined Pylance (reportUndefinedVariable) [Ln 7, Col 16],
How can i solve this ?
Best regards,
Having a mirror would be quite cool
As of now, Electric and magnetic field are static, Dynamic field with moving charges will be a good addition.
You can't execute any methods once the animations for each object are started. Example:
class WaveScene(Scene):
def construct(self):
wave = StandingWave(2, color=YELLOW)
self.add(wave)
wave.start_wave() # Troublemaker
self.wait(1)
self.play(
ApplyMethod(wave.shift, DOWN)
)
self.wait(10)
The wave doesn't move down when using wave.start_wave()
before.
From discord user Naw Sai: SVGMobjects don't work as rigid bodies.
This is because the function SpaceScene.make_rigid_body
takes the whole family of the mobject and applies the rigid property; which explains the explosion, as overlap of rigid bodies are considered high powered collisions.
I think a good approach would be to make the function disregard families; if the children are intended to be rigid, then an unpacking operator should be used.
Before:
a = VGroup(Circle(), Square().shift(UP*2))
self.make_rigid_body(a)
After:
a = VGroup(Circle(), Square().shift(UP*2))
self.make_rigid_body(*a)
Exactly as stated in the title. I'm thinking about making it like a chain, using some constraints, but add smaller and more segments. Is this a viable approach? Thank you for all your work thus far.
I tried one of the examples and get an error. It was previously working (althought it´s been a long time since I ran it)
So whenever a Charge
object is instanciated, the attribute point
is set:
manim-physics/src/manim_physics/electromagnetism.py
Lines 16 to 40 in 70ab45a
but this attribute is not updated when using methods such as move_to
or shift
:
class Sample(Scene):
def construct(self):
charge = Charge()
print(charge.point)
charge.shift(UP)
print(charge.point)
>>[0. 0. 0.]
>>[0. 0. 0.]
This implies some incorrect behaviour e.g. when using ElectricField.get_force_on_charge
:
class Sample(Scene):
def construct(self):
charge_1 = Charge(add_glow=False)
charge_2 = Charge(add_glow=False).shift(UP)
field = ElectricField(charge_1)
f = field.get_force_on_charge(charge_2)
self.add(charge_1, charge_2, field, f)
You can see here that the f
vector is still located on the origin, where the charge_2
was previously located.
This happens because the code of the get_force_on_charge
method is using the charge.point
attribute L147:
manim-physics/src/manim_physics/electromagnetism.py
Lines 129 to 149 in 70ab45a
So maybe to fix this the methods moving the object such as shift
, move_to
, to_corner
should be overrided? The thing is we can't be 100% sure that all the methods modifying the object's position have been taken into account. Maybe there's a more general way of fixing this.
I want to turn off gravity for one scene, but methods from pymunk docs does not works.
Firstly I tryied to change scene space gravity paramether in construct method:
def construct(self):
self.space.gravity = 0, 0```
But it doesn't help
Then i tried to override init method for Space scene class, but it did not bring any result
def __init__(self, renderer=None, **kwargs):
self.space = Space(gravity=(0, 0))
super().__init__(renderer=renderer, **kwargs)
Full code:
from manim import *
from manim_physics import *
class FirstScene(SpaceScene):
def __init__(self, renderer=None, **kwargs):
self.space = Space(gravity=(0, 0))
super().__init__(renderer=renderer, **kwargs)
def construct(self):
self.space.gravity = 0, 0
c1 = Circle(color="red").shift(2* LEFT)
c2 = Circle(color="blue").shift(RIGHT)
self.make_rigid_body(c1, c2)
c1.body.velocity = (1, 0)
self.wait(10)
Manim is currently at version 0.18.0.post0, and remains compatible with manim-physics.
However manim-physics' pyproject specifies:
manim = "^0.17.3"
which causes that any attempt to install manim-physics downgrades installed manim to 0.17.13, and any attempt of upgrading manim after that issues a warning about incompatible requirements with manim-physics.
I think the line in pyproject can be safely changed to:
manim = "^0.17.3,<0.19.0"
具体问题发送到群里面了并且私信了
make_rigid_body(string) 只会让最后一个字符掉下去
解决办法:
rigid_mechanics.py 第 56 行和 57 行应该被 indent
要不然只会让字符串的最后一个字符得到效果 而不是每一个字符
So I'm currently trying to implement a homogeneous magnetic field. However, I can't get it to work. And basically my question is: Is it even possible to create a homogeneous magnetic field using this library?
The closest thing I could get is this (even tough I needed to remove this if-statement in electromagnetism.py, btw, why did you add it?):
from manim import *
from manim_physics import *
class HorseShoeMagnet(VGroup):
def __init__(
self,
width: float = 6,
height: float = 6,
bar_width: Optional[float] = None,
bar_height: Optional[float] = None,
field_x_padding: Optional[float] = None,
field_y_padding: Optional[float] = None,
field_density: float = 2,
magnets: list[BarMagnet] = None,
create_bar: bool = True,
**kwargs
):
magnets = magnets or []
field_x_padding = field_x_padding or .3
field_y_padding = field_y_padding or .3
bar_width = bar_width or 1
bar_height = bar_height or 1
field_width = width - bar_width
field_height = height - (bar_height * 2)
bar_magnets = [*magnets]
surrounding_rectangle = Rectangle(width=0, height=height)
# Ensures that there is a field
self.bar_magnet = BarMagnet(width=width, height=height * 5)
if create_bar:
bar_magnets.insert(0, self.bar_magnet)
self.field = BarMagneticField(
*bar_magnets,
x_range=[
-(field_width / 2),
(field_width / 2 - field_x_padding),
1 / field_density
],
y_range=[
-(field_height / 2 - field_y_padding),
(field_height / 2 - field_y_padding),
1 / field_density
]
)
self.north_rectangle = Rectangle(
width=field_width,
height=bar_height,
fill_opacity=1,
color=RED,
stroke_width=0,
)\
.align_to(surrounding_rectangle, DOWN)
self.north_side_wall = Rectangle(
width=bar_width,
height=height / 2,
fill_opacity=1,
color=RED,
stroke_width=0,
)\
.align_to(self.north_rectangle, RIGHT + DOWN)\
.shift(RIGHT)
self.north_label = Tex("N").next_to(self.north_rectangle, ORIGIN)
self.north_parts = VGroup(
self.north_rectangle,
self.north_side_wall,
)
self.south_rectangle = Rectangle(
width=field_width,
height=bar_height,
fill_opacity=1,
color=BLUE,
stroke_width=0,
)\
.align_to(surrounding_rectangle, UP)
self.south_side_wall = Rectangle(
width=bar_width,
height=height / 2,
fill_opacity=1,
color=BLUE,
stroke_width=0,
)\
.align_to(self.south_rectangle, RIGHT + UP)\
.shift(RIGHT)
self.south_label = Tex("S").next_to(self.south_rectangle, ORIGIN)
self.south_parts = VGroup(
self.south_rectangle,
self.south_side_wall,
)
super().__init__(**kwargs)
self.add(
self.field,
VGroup(
self.north_parts,
self.south_parts,
),
self.north_label,
self.south_label
)
self.add(*magnets, self.bar_magnet.set_opacity(.2))
class FirstFormulaExplainedScene(Scene):
def construct(self):
magnet = HorseShoeMagnet(field_density=8, magnets=[BarMagnet().scale(.1)])
self.add(magnet)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.