Now the question is how can I calculate the force of magnet A on magnet B and vice versa?? (Appreciate if some idea on Torque also is given).. I have got all the values like, cross section of the magnets, the separation b/w the magnets, the angle difference between the two magnets, (Bx, By) at any point etc.
Glad to see your project has been moving along successfully.
To answer your question, take a look at
this Wikipedia article . The punchline is the equation
F = I (L x B)
which relates, for the three-dimensional case,
F, the force vector acting on the wire
L, the displacement vector from the start of the wire to the end,
B, the magnetic field vector where the wire is, and
I, the current carried by the wire (a scalar).
The idea will be this: You're approximating your magnets as solenoids -- collections of many wires, which in this case are perpendicular to the plane -- so what you can do is just compute the force vector acting on each of these wires. The sum of all the forces acting on the wires of the solenoid is the net force on the magnet. Since you know the displacement of each wire from the magnet's center of mass, you can also compute a torque due to each (Remember
tau=rxF), and add these up to compute the net torque on the magnet about its center of mass.
Finally, the force equation I gave you is 3d, and your simulation is 2d, so we'll need to interpret the above equation appropriately. This means,
L = (0,0,1)
or
L = (0,0,-1)
depending on whether the wire is going into or out of the plane, and, if your magnetic field at the wire is the 2d vector (bx, by), then
B = (bx, by, 0) .
The vector F that you get will lie in the plane; i.e., it will have the form,
F = (fx, fy, 0)
so you will be able to forget the third component and just consider the force vector (fx, fy).
To summarize, what you're going to want to do is,
...For each magnet M
...{
........Force_on_M = (0,0)
........Torque_on_M = 0
........For each wire W comprising the solenoid you're using to approximate M
........{
............Compute the force on W using the equation F = I (L x B)
............and the torque on the magnet tau=rxF due to it.
............Force_on_M += F
............Torque_on_M += tau
........}
...}
Finally, let me mention the approximations I'm making:
1.) I'm assuming all the fields are slowly-changing. In real life, a changing magnetic field creates an electric field (which, if changing, creates a magnetic field, and so on); this is what constitutes electromagnetic waves. This simulation will not deal with that.
2.) I'm being a little sloppy with the third dimension.
Nevertheless, I think all the basic ideas are here.