Skip to content

Commit

Permalink
Magnetic fields should accept multiple wires (#35)
Browse files Browse the repository at this point in the history
* fix

* test

* control data

* changelog
  • Loading branch information
icedcoffeeee authored Aug 1, 2024
1 parent cb71a9a commit 2876741
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
7 changes: 7 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
Changelog
=========

**v0.4.1**
==========
Bugfix
------
- `#34 <https://github.com/Matheart/manim-physics/pull/35>`_ : Magnetic fields
now accept multiple wires

**v0.4.0**
==========
Breaking Changes
Expand Down
15 changes: 8 additions & 7 deletions manim_physics/electromagnetism/magnetostatics.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,12 @@ def _field_func(
currents: Iterable[float],
):
B_field = np.zeros(3)
for (r0, r1), I in it.product(*dls, currents):
dl = r1 - r0
r = p - r0
dist = np.linalg.norm(r)
if dist < 0.1:
return np.zeros(3)
B_field += np.cross(dl, r) * I / dist**4
for dl in dls:
for (r0, r1), I in it.product(dl, currents):
dr = r1 - r0
r = p - r0
dist = np.linalg.norm(r)
if dist < 0.1:
return np.zeros(3)
B_field += np.cross(dr, r) * I / dist**4
return B_field
Binary file not shown.
9 changes: 9 additions & 0 deletions tests/test_electromagnetism.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,12 @@ def test_magnetic_field(scene):
wire = Wire(Circle(2).rotate(PI / 2, UP))
field = MagneticField(wire)
scene.add(field, wire)


@frames_comparison(base_scene=ThreeDScene)
def test_magnetic_field_multiple_wires(scene):
wire1 = Wire(Circle(2).rotate(PI / 2, RIGHT).shift(UP * 2))
wire2 = Wire(Circle(2).rotate(PI / 2, RIGHT).shift(UP * -2))
mag_field = MagneticField(wire1, wire2)
scene.set_camera_orientation(PI / 3, PI / 4)
scene.add(wire1, wire2, mag_field)

0 comments on commit 2876741

Please sign in to comment.