Vector field for magnetic di-poles

Started by
17 comments, last by aditya369 12 years, 7 months ago
[font="Trebuchet MS"]Thanks Emergent for the ideas, but I am afraid, again all these sound very new to me unfortunately.

I pity myself for neglecting physics and graphics :( in my school. Nevertheless, I have to complete my project I am working on ASAP as I am running out of time pretty quickly. Unavoidably, I have wasted a week searching for a prototype app that nearly suites my requirement but in vain. I go very anxious these days.

At this point, Can I ask you to involve in some hardcore "OpenGL, GLUT + Physics + Math" discussions with me!!? You might have to adjust with me for a week(or two) probably. Consider this as my humble request. Thanks.

So, let me start with a questionnaire of all my little knowings..
[/font]
  • [font="Trebuchet MS"]I understand that C/C++ is the logic behind the scene and OpenGL is the front end for my visualization. Am I write?
    Which one is it good to work on - C or C++? Specifically, VC(Win32) or VC++(MFC)?

    Somewhere I've read that MFC is not so good!!?? In that case, developing a gaming app in simple C - with out OOPS - isn't going to be too hard?

    [/font]
  • [font="Trebuchet MS"]Is there any specific design (pattern) we need to abide when developing a good graphics application for such interactions? Basically, my C++ classes and the graphics objects have to communicate and do the needful in a very reliable way!? Just a thought.

    [/font]
  • [font="Trebuchet MS"]The approach in my mind (pls correct wherever required.)
    [/font]
    1. [font="Trebuchet MS"]In a 3D, create an XY plane(say 500 x 500) which can be rotated and viewed from any angle using mouse.[/font]
    2. [font="Trebuchet MS"]Create an object "Bar Magnet1 (cuboid with N and S)" and place it on the above plane, say at origin - center of the screen.[/font]
    3. [font="Trebuchet MS"]Now this magnet has got some properties like B, H, magnetic moment etc etc. (I need some help here on which properties really play an important role).[/font]
    4. [font="Trebuchet MS"]Calculate the field intensity using differential equations. Which algorithm to be considered?
      Okay, but what about the direction of the field - this is important as to show attraction or repulsion. How can we get the direction? This is just the angle wrt an imaginary line in the 2D plane, right?[/font]
    5. [font="Trebuchet MS"]Now this field reduces with distance. To visualize this in the 3D picture, which is better to go for? Arrow plot or LIC and how to achieve that?

      [/font]
  • [font="Trebuchet MS"]Right now gamedev is the ONLY hope to complete my project on time - atleast to get some idea on what to do. If you could point to relevant demos/tuts and help me connect the dots, that would be real help.[/font]
[font="Trebuchet MS"]Thanks for all your help!![/font]
Advertisement
Is someone there to guide!!? OR ATLEAST POINT ME TO SOME GOOD TUTORIAL ON SIMULATING DYNAMICS. Whatever you know might turn out helpful to me.
Ok, let's start simple then.

My advice:

1.) Install Visual C++ Express.

2.) Follow this tutorial . It will walk you through setting up a window and doing simple drawing using OpenGL.

3.) Write a function to draw a vector field that you have stored in an array. Forget the fancy stuff; just draw a bunch of arrows. Test it on a simple vector field, e.g. u=-y, v=x.

4.) Write a function to generate the magnetic field corresponding to a single, infinite wire perpendicular to the plane. It is,

B = (mu_0 I) /(2 pi ||r||^2) J r

where 'r' is the 2d displacement vector from the point where the wire intersects the plane, I is the current, mu_0 is the magnetic permeability constant, and J = [0 1; -1 0] is a 90-degree rotation matrix. Test it using the function you produced in part #3.

5.) Write a function to generate the magnetic field due to a solenoid. To do this, just add up many of the fields that you figured out in part #4. This image shows you how. You are approximating your bar magnet by a solenoid, so this produces the field due to a single bar magnet.

6.) Write a function to generate the magnetic field due to a number of bar magnets. To do this, add up a number of the fields you got in part #5.

Ultimately, you're going to need to figure out C++, the basics of the OpenGL API, and a little bit of physics, to pull this off. If you need more resources... For the physics, my suggestion is to get a simple -- say, high-school- or college-freshman -level -- textbook. For C++, the tutorials here are a good place to start. For OpenGL, you might also want to check out the tutorials here. Still, don't let this scare you; walk through the steps I listed, and you should be able to do this. And by the time you get to #6, you should be comfortable enough with what you're doing to direct yourself.

Good luck!

Ok, let's start simple then.

My advice:

1.) Install Visual C++ Express.

2.) Follow this tutorial . It will walk you through setting up a window and doing simple drawing using OpenGL.

3.) Write a function to draw a vector field that you have stored in an array. Forget the fancy stuff; just draw a bunch of arrows. Test it on a simple vector field, e.g. u=-y, v=x.

4.) Write a function to generate the magnetic field corresponding to a single, infinite wire perpendicular to the plane. It is,

B = (mu_0 I) /(2 pi ||r||^2) J r

where 'r' is the 2d displacement vector from the point where the wire intersects the plane, I is the current, mu_0 is the magnetic permeability constant, and J = [0 1; -1 0] is a 90-degree rotation matrix. Test it using the function you produced in part #3.

5.) Write a function to generate the magnetic field due to a solenoid. To do this, just add up many of the fields that you figured out in part #4. This image shows you how. You are approximating your bar magnet by a solenoid, so this produces the field due to a single bar magnet.

6.) Write a function to generate the magnetic field due to a number of bar magnets. To do this, add up a number of the fields you got in part #5.

Ultimately, you're going to need to figure out C++, the basics of the OpenGL API, and a little bit of physics, to pull this off. If you need more resources... For the physics, my suggestion is to get a simple -- say, high-school- or college-freshman -level -- textbook. For C++, the tutorials here are a good place to start. For OpenGL, you might also want to check out the tutorials here. Still, don't let this scare you; walk through the steps I listed, and you should be able to do this. And by the time you get to #6, you should be comfortable enough with what you're doing to direct yourself.

Good luck!


Great and patient reply .. As a fellow member , i would like to thank u
gamedev is really gonna help everyone.. i suggest it for every graphics programmer.
It really wouldn't hurt to read a textbook on Differential Equations.

Also, you might want to see Chapter 20: Scientific Visualization in Advanced Graphics Programming Using OpenGL. The book is a goldmine.

Ok, let's start simple then.

My advice:

1.) Install Visual C++ Express.

2.) Follow this tutorial . It will walk you through setting up a window and doing simple drawing using OpenGL.

3.) Write a function to draw a vector field that you have stored in an array. Forget the fancy stuff; just draw a bunch of arrows. Test it on a simple vector field, e.g. u=-y, v=x.

4.) Write a function to generate the magnetic field corresponding to a single, infinite wire perpendicular to the plane. It is,

B = (mu_0 I) /(2 pi ||r||^2) J r

where 'r' is the 2d displacement vector from the point where the wire intersects the plane, I is the current, mu_0 is the magnetic permeability constant, and J = [0 1; -1 0] is a 90-degree rotation matrix. Test it using the function you produced in part #3.

5.) Write a function to generate the magnetic field due to a solenoid. To do this, just add up many of the fields that you figured out in part #4. This image shows you how. You are approximating your bar magnet by a solenoid, so this produces the field due to a single bar magnet.

6.) Write a function to generate the magnetic field due to a number of bar magnets. To do this, add up a number of the fields you got in part #5.

Ultimately, you're going to need to figure out C++, the basics of the OpenGL API, and a little bit of physics, to pull this off. If you need more resources... For the physics, my suggestion is to get a simple -- say, high-school- or college-freshman -level -- textbook. For C++, the tutorials here are a good place to start. For OpenGL, you might also want to check out the tutorials here. Still, don't let this scare you; walk through the steps I listed, and you should be able to do this. And by the time you get to #6, you should be comfortable enough with what you're doing to direct yourself.

Good luck!


Thank you Emergent for all the details! I am seeing improvement myself. So far have been able to come up with a very simple vector field like the one attached. You are really cool!! Thanks.

I will let you know if I am stuck somewhere.

[attachment=1723:simple_vector_field.PNG]

[quote name='Emergent' timestamp='1300747795' post='4788853']
Good luck!


Thank you Emergent for all the details! I am seeing improvement myself. So far have been able to come up with a very simple vector field like the one attached. You are really cool!! Thanks.

I will let you know if I am stuck somewhere.

[attachment=1723:simple_vector_field.PNG]
[/quote]

Hi Emergent,

Hope you are doing good!!
  1. I have modeled a pseudo magnetic field in OpenGL, which looks similar to this la9Pt.jpg
  2. The vectors are discretely calculated by retrieving appropriate values from a data base which has the Bx, By values of a magnet (modeled in FEMM).
  3. 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.

Google dint help me. So, posting here and SO..

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.

Nevertheless, I think all the basic ideas are here.


Oh my... you are my HERO!! Thanks a lot Emmy!
Will try out and let you know :)..

This topic is closed to new replies.

Advertisement