# Magnetic force and torque for 2D neodymium ball simulator

I'm trying to write a simulator for neoballs. I'm doing only 2D for a start, in which each ball has a magnetic moment, m, that is in the x-y plane.

The simulator will use time-step integration at 60 fps, and typical collision detection stuff. For the magnetism I intend to compute force and torque between each pair of balls on every frame.

I think it will be ok to approximate each little ball as a "point dipole". What is the formula for force and torque?

For the force I have this from wikipedia

${\displaystyle \mathbf {F} (\mathbf {r} ,\mathbf {m} _{1},\mathbf {m} _{2})={\frac {3\mu _{0}}{4\pi r^{5}}}\left[(\mathbf {m} _{1}\cdot \mathbf {r} )\mathbf {m} _{2}+(\mathbf {m} _{2}\cdot \mathbf {r} )\mathbf {m} _{1}+(\mathbf {m} _{1}\cdot \mathbf {m} _{2})\mathbf {r} -{\frac {5(\mathbf {m} _{1}\cdot \mathbf {r} )(\mathbf {m} _{2}\cdot \mathbf {r} )}{r^{2}}}\mathbf {r} \right]}$

But I think it gives the wrong answer. No matter what the direction of $\mathbf{m} _{1}$ or $\mathbf{m} _{2}$, I think the force must be always parallel to r to conserve angular momentum. However, suppose $\mathbf{m} _{1}$ is parallel to r and $\mathbf{m} _{2}$ is perpendicular:

All terms except the first vanish, and F is in the direction $\mathbf{m} _{2}$, which is not possible? Common sense tells me F should be zero in this case! What am I doing wrong?

Also I need a formula for the torque. I know $\mathbf{\tau=m\times B }$, and on the same wiki page I got

${\displaystyle \mathbf {B} (\mathbf {m} ,\mathbf {r} )={\frac {\mu _{0}}{4\pi r^{3}}}\left(3(\mathbf {m} \cdot {\hat {\mathbf {r} }}){\hat {\mathbf {r} }}-\mathbf {m} \right)}$

(I dropped the dirac term, because I don't need it).

I haven't tried it yet, but I think I can compute the the torque around the center of mass of $\mathbf{m} _{2}$ with $\mathbf{\tau=m _{2}\times B(m _{1}, r) }$ where r is position of $\mathbf{m} _{2}$ relative to $\mathbf{m} _{1}$. Since all the balls have identical mass and magnetism, the torque on $\mathbf{m} _{1}$ is the same but with opposite sign.

Does that look reasonable?

EDIT: the above force formula seems to be rubbish, but the flux density(B) is reasonable. I'm wondering if I can just use $\mathbf{\tau=m\times B }$ for torque and $\mathbf{F=(m\cdot B)\hat {\mathbf {r} } }$ for force. It has a nice symmetry, and gives good results in the simulation.

EDIT2 Another curious contradiction. According to this wiki page, the potential energy of a magnetic field is given by:

${\displaystyle H=-{\frac {\mu _{0}}{4\pi |{\mathbf {r}}|^{3}}}\left(3({\mathbf {m}}_{1}\cdot {\hat {\mathbf {r}}})({\mathbf {m}}_{2}\cdot {\hat {\mathbf {r}}})-{\mathbf {m}}_{1}\cdot {\mathbf {m}}_{2}\right)}$

And this implies as long as m2 is perpendicular to m1 and r, the potential energy is ZERO. Since force is the gradient of potential over space, then the force must be also zero in that case. What am I misunderstanding?

• $F = (m \cdot B) \hat r$ can't be right. The energy is U = -$m \cdot B$, so the force should be $F = -\nabla U = m \cdot \nabla B$, which if you work it out I'm assuming will give you that dipole-dipole force formula. – adipy Jul 18 '16 at 19:07
• @adipy thanks. great suggestion! my vector calculus is a little rusty... i'll try tho – John Henckel Jul 18 '16 at 19:25

But I think it gives the wrong answer. No matter what the direction of $\mathbf{m} _{1}$ or $\mathbf{m} _{2}$, I think the force must be always parallel to r to conserve angular momentum.

The force acting on magnetic moment due to another magnetic moment is not always parallel to the line that connects them. This does not violate conservation of angular momentum though. Although the above formulae suggest the magnets are points so that only orbital angular momentum is relevant, the magnets in fact have rotational angular momentum as well.

When the magnets move due to mutual force, orbital angular momentum of magnets (treated as moving points) changes, but the magnets also can rotate so rotational angular momentum of the magnets may change as well.

Since the system is equivalent to system of electric dipoles and can be described via Coulombic forces, it conserves both energy and angular moment. When total angular momentum - sum of orbital and rotational contributions - is calculated, the result should not change in time, if the motions are quasistatic.

This will create spontaneous spin. It would not conserve the angular momentum of the system. All you would need to do is put a wooden rod between them and voila! perpetual motion machine!!

That's a good puzzle. The resolution is that the orbital spin of the system, if it is allowed to occur, is compensated by opposite rotational spin of the individual magnetic moments. If there is a rod connecting centers of the magnets while allowing them to rotate around the pivots on both ends of the rod, the rod will alternate between clockwise and counterclockwise motion, while the magnets will be doing the same in the opposite sense, so total angular momentum will be conserved.

If the rod and the magnets are cemented into a rigid body so no motion of magnets relative to the rod is allowed, no motion of the system will occur at all; the rod will experience mechanical forces of shear and will act back on the magnets, cancelling the EM forces that tend to move them (see also picture).

• I added a picture to the question. I'm pretty sure F should be zero when the magnets are perpendicular. Right? – John Henckel Jul 18 '16 at 13:27
• @JohnHenckel, I believe the forces acting on the magnets in the picture will point vertically, but their orientation will be opposite, that is, force $\mathbf F_2$ should point downwards. Why do you think the forces should be zero? – Ján Lalinský Jul 18 '16 at 15:59
• Thanks for your patience. I think it must be zero, because I think it must only act along the line between the centers of mass. If F2 acts perpendicular to r (as in the picture), then by Newton's 2nd law, F1 must act in the opposite direction. This will create spontaneous spin. It would not conserve the angular momentum of the system. All you would need to do is put a wooden rod between them and voila! perpetual motion machine!! – John Henckel Jul 18 '16 at 18:29
• i just added EDIT2, showing that the potential energy is zero. – John Henckel Jul 18 '16 at 18:51
• That's a good puzzle. The resolution is that the orbital spin of the system, if it is allowed to occur, is compensated by opposite rotational spin of the individual magnetic moments. If there is a rod connecting centers of the magnets while allowing them to rotate around the pivots on both ends of the rod, the rod will alternate between clockwise and counterclockwise motion, while the magnets will be doing the same in the opposite sense, so total angular momentum will be conserved. – Ján Lalinský Jul 18 '16 at 21:27