Vector field for magnetic di-poles

Started by
17 comments, last by aditya369 12 years, 7 months ago
Hi,

Just registered and writing my first post in GameDev!! :rolleyes:

Problem Statement
I wanted to simulate the magnetic field lines (vectors, i.e, direction and intensity) in [color="#ff8c00"]OpenGL using the [color="#ff8c00"]Line Integral Convolution technique. Something like this "http://www.mare.ee/indrek/ephi/".

Questions
  1. Is LIC a library? If yes, where can I find one for VC++ 2010 ultimate?
  2. An example/tutorial explaining the usage in 2D and 3D(if possible).

If I seem to sound naive and abstract in my talking please forgive me and provide me necessary pointers to start with! :(

Thanks,
Aditya
Advertisement
Moved to Maths and Physics, as the question is not related to OpenGL.
I'm confused to what you actually want. LIC is a visualization technique. Do you want to create a simulation that constructs the vector field? Or have you got already got the vector field data and want to perform LIC to visualize it? Or both?

Assuming you are talking about the visualization aspect, finding an off-the-shelf LIC implementation might be hard due to varying grid types and data formats for the vector field data. Here is a link to some LIC C code (it's not OpenGL though). It might still be useful for you to get a grasp of the idea.

LIC code

If this isn't helpful let me know and I will dig out my C++/OpenGL implementation of LIC for you. It's not a stand alone library but you can have the class source to see how I did it. It's also not the best implementation, as it was a quick hack, but the results looked good and it ran at a reasonable rate.

Does it have to be LIC? You could try something IBFV (theres some example code on there too), which gives similar results but should be faster.
If you're only interested in divergence-free flows like magnetic fields, why not construct streamfunctions and use marching squares to draw the level sets? This will give you nice global properties; e.g., integration error will never cause field lines to cross, etc.
Thank you Unicron!! That was very informative!!


I'm confused to what you actually want. LIC is a visualization technique. Do you want to create a simulation that constructs the vector field? Or have you got already got the vector field data and want to perform LIC to visualize it? Or both?

[color="#2f4f4f"]Let me start from the beginning.
  1. [color="#2f4f4f"]My requirement is to build a simple simulation of magnetic field lines between two or three bar magnets in OpenGL.
  2. [color="#2f4f4f"]Also, if the magnets are too close to each other, based on their alignment, they should..
    • [color="#2f4f4f"]attract, or
    • [color="#2f4f4f"]repel, and/or
    • [color="#2f4f4f"]turn i.e. show some torque on its axis.
  • [color="#2f4f4f"]As a first step, I am searching for some implementation which has a plane (say xy-plane) with grid lines and each grid having an associated vector. These vectors will be later used when a magnet is placed on the plane to show the direction of the field and its intensity. It is here I came to know about LIC.
  • [color="#2f4f4f"]Now, I would like to understand more about LIC from an already existing tutorial (if one exists). So, in essence, "I was asking how to create a simulation that constructs the vector field using the LIC technique".

    Question
    From what you say, LIC is used only after we have a vector field in hand??


    If this isn't helpful let me know and I will dig out my C++/OpenGL implementation of LIC for you. It's not a stand alone library but you can have the class source to see how I did it. It's also not the best implementation, as it was a quick hack, but the results looked good and it ran at a reasonable rate.
    [color="#2f4f4f"]Yes. Please do share your sample program. I will run it and see if it can be helpful.


    Does it have to be LIC? You could try something IBFV (theres some example code on there too), which gives similar results but should be faster.

    [color="#2f4f4f"]
    Not specifically. Just trying different options. I am very new to graphics programming. So, do not know which is good or bad. Trying everything I come across. IBFV is good. I tried it on my system and it performs well.

    If you're only interested in divergence-free flows like magnetic fields, why not construct streamfunctions and use marching squares to draw the level sets? This will give you nice global properties; e.g., integration error will never cause field lines to cross, etc.


    [color="#2f4f4f"]Hmm.. Looks like this sounds too techy to me! Can you explain to me in detail on stream functions, marching squares, level sets etc. Any good material online? Pls refer my above post for my actual requirement in case you wanted more details. Thanks.
    [color="#2f4f4f"]
    Question
    From what you say, LIC is used only after we have a vector field in hand??
    [color="#2F4F4F"][color="#000000"]


    Yes, LIC is a visualization technique. It does not create a vector field. LIC takes as input a reference image (usually a noise texture) and a vector field. The reference image is basically then smeared along the vector field.
    A quick clarification -

    You don't create a simulation "in" OpenGL, you create a simulation with a programming language such as C++ and "use" OpenGL to render a visual representation of the state of the simulation.


    [color="#2f4f4f"]Unicron, can you give me some ideas on continuing..
    1. [color="#2f4f4f"]My vector field idea is derived from here. Run this and you see a vector per grid.
    2. [color="#2f4f4f"]If my plane has such a grid and respective vectors, I will control them to behave as I say.
    [color="#2f4f4f"]Give me some ideas for the above implementation. Let me also know your opinions.

    [color="#2f4f4f"]Hmm.. Looks like this sounds too techy to me! Can you explain to me in detail on stream functions, marching squares, level sets etc. Any good material online? Pls refer my above post for my actual requirement in case you wanted more details. Thanks.


    Really, the word "streamfunction" is used in fluid dynamics; in electromagnetics it's called the "magnetic potential," so that's the phrase I should have used; either way, the math is the same.

    You're working in 2d? The idea is that you use a scalar function 'phi' to describe the magnetic field 'B' in the following way:

    B = J grad phi

    J = [0 1; -1 0] is a 90-degree rotation matrix (here, I used a semicolon to separate rows of the matrix). In other words, you compute the gradient, rotate it 90 degrees (so now you have a vector pointing along the level set), and say that this is the magnetic field. The field lines are just the level sets of 'phi.'

    You can draw the level sets, like I said earlier, using the Marching Cubes algorithm. It's described here.

    All this leaves is how to actually compute 'phi.' The idea here is simple: Figure out how to compute one analytically for a single bar magnet; then add 'em up for all your bar magnets. I would model a bar magnet as a solenoid.

    I guess the only thing I haven't explained in this post is exactly what the magnetic potential due to a solenoid is. For now, I'll leave that to you! :-)

    This topic is closed to new replies.

    Advertisement