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 :)
https://www.youtube.com/watch?v=92mLz4GMUPE
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)
https://www.youtube.com/watch?v=glxTVMenEWU
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)/r^{5} - m/r^{3}
Calculating the torque on a dipole is very easy too (=m^B)
2) But how do I calculate the force on a dipole =\nabla(m.B) ?
How do I calculate the gradient of m.B ?
3) Also, on the wikipedia, they define the magnetic field as B=\nabla^A with A=m^r/r^{3}.
How do they deduce the equation above B=3r(m.r)/r^{5} - m/r^{3} ?
4) Any ideas to improve the simulation ?