1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Simulating toy magnet balls ? (eg: Zen magnets)

  1. Apr 14, 2012 #1
    I'd like to simulate the interaction between these magnetic balls on my computer.
    I suppose they are magnetic dipoles, how would I go about finding out the forces applying between 2 of them in a specific configuration ?

    Do I need to find the magnetic field and then apply the Lorentz force equation ? How would I find the magnetic field ?

    Thanks !
  2. jcsd
  3. Apr 14, 2012 #2
    Ferromagnetism s notoriously difficult to analyze, because it's caused by extremely complex (quantum) behavior of the electrons in the metal.

    Even very approximate equations would be nonlinear, because the magnetization of them changes based on the applied field.

    Even measuring the magnetic field is notoriously difficult, for similar reasons - which is why when buying magnets, you generally don't get that type of information.

    However, don't let that discourage you... If you're simulating this as a "toy" -- e.g. You're not going to be using the output for anything -- you could probably come up with a workable empirical model. You might start by measuring the forces between two magnets at varying distances using pendulums, springs, or even a scale, then plug those into Newton's 2nd law.

    If you get anything working, be sure to share -- make it JavaScript so I can try it on my iPad ;).

    Good luck,
  4. Apr 15, 2012 #3
    Indeed, it's just a toy, I don't need to be accurate here.
    Hopefully it shouldn't be too hard. I'll try to make a prototype in c# using farseer physic engine. And if it turns out ok, I'll make an app for my shiny new iPad 3 :)
    I'll limit myself to 2 dimensions. I'm really curious to see if I can simulate the crystal like arrangements of the real toy. If it works well, I could easily imagine a bridge builder like clone using lots of little magnets :)
    I'll keep you posted
  5. Apr 15, 2012 #4
    Alright, I got a prototype working, it's pretty fun.
    I wish I didn't have to work tomorrow, I would port it to the iPad straight away :)
    Here this structure is not terribly stable which makes sense as the hexagon with a ball in the middle is not a planar structure with the real balls (you would need 2*pi balls around the central ball for it to be planar)
    Source code: https://rapidshare.com/files/434299666/MagnetProto.rar
    Exe: https://rapidshare.com/files/3871493948/MagnetProtoExe.rar
    space: create magnet
    D: delete magnet
    F: fix magnet's position/orientation

    Basically, I model the magnets by an electric dipole that's about 2x as small as the sphere (parameter DipoleLength). It works, but it's not very good yet:
    - I cannot do the basic triangle figure (it's not very stable already with real balls)
    - Because of arithmetic error, some configurations never stop turning
    - It's just too wiggly. If I increase the force, it tends to blow up though

    I'm still not finished playing with the parameters yet. But still I have a few questions

    1) I'd like to use the magnetic equations instead, do you think I'll get a more realistic result ?

    So calculating the magnetic field is easy (yellow arrows in the video) B=3r(m.r)/[itex]r^{5}[/itex] - m/[itex]r^{3}[/itex]
    Calculating the torque on a dipole is very easy too (=m^B)

    2) But how do I calculate the force on a dipole =[itex]\nabla[/itex](m.B) ?
    How do I calculate the gradient of m.B ?

    3) Also, on the wikipedia, they define the magnetic field as B=[itex]\nabla[/itex]^A with A=m^r/[itex]r^{3}[/itex].
    How do they deduce the equation above B=3r(m.r)/[itex]r^{5}[/itex] - m/[itex]r^{3}[/itex] ?

    4) Any ideas to improve the simulation ?
    Last edited: Apr 15, 2012
  6. Apr 15, 2012 #5
    Rectification, I managed to make the triangle. Reducing the size of the dipole and increasing the magnetic force did the trick. I suppose the model gets more accurate when the dipole gets really small.
  7. May 5, 2012 #6
    Unfortunately it doesn't translate to 3 dimensions.
    I've done a little app for iPad using the bullet physic engine.
    And for some reason it's not stable at all and I can't figure out why.

    I'm pretty sure I got the equations right. I've played with all the parameters but the magnets spin out of control so much. You guys have any idea why ?

    I should maybe rewrite it on my PC in a different framework. Maybe bullet is not appropriate for that.
  8. May 6, 2012 #7


    User Avatar
    2017 Award

    Staff: Mentor

    Using diples is a nice approximation for large distances. But it underestimates the forces when the magnets are close to each other (especially when they touch each other). This is probably the reason why you can bend your lines and circles in ways the real magnets do not allow (without constant external forces).

    Maybe you can improve it with additional terms which describe these contacts.
    Multiple dipoles within the volume might be an interesting concept.

    What happens in your simulation if you make two parallel lines of magnets with the same/opposite magnetic orientation? Do you get the correct result? (I assume that you have real magnets or at least know how they behave - otherwise, ask)
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook