Magnetic Field Lines!

So…recently I have been looking for a specific project that would force me to learn new skills in Blender, revisit lost skills in mathematics, and learn some programming while I was at it.

I think I have settled on: Magnetic Field Lines (MFL).

If you look online, almost all images of MFL are 2-dimensional, even when the object emanating the field is rendered in 3-dimensions, like this:

http://bugman123.com/Physics/Solenoid.jpg

Now, aside from the fact that I clearly don’t YET have the skills to do this, and barring the notion that it still might look like complete crap…I still want to try.

I have 3ish potential ideas in mind for this, and I am posting in the Materials forum based on my first and preferable idea.

  1. Might this be possible to do with a Volumetric shader? At least for a simple case, might I be able to transcribe the equations for the field lines into 3 dimensions and assign it to the density of a volumetric shader?

  2. What about OSL? Can OSL work with Volumetrics?

or, 3) I know this isn’t necessarily for this sub-forum…but particles? I would much rather try to do this with OSL/volumetrics…but…

What do people think? Any ideas would be greatly appreciated.

1 Like

if you find me the nice polar equations for it I might be able to make a script for this

saw something in the physic particles

happy bl

did a script for 2D lines


should be possible to do it for 3D lines

is it what you had in mind ?

happy bl

1 Like

Nice one ricky!

It’s close, in a certain sense. (If it is a script, if possible I would like to see the code). And with that, essentially you could revolve each line on the perpendicular axis and achieve a 3d version.

Although, it is not quite what I would like to accomplish. I’m not even sure if my REAL end goal would even be possible…but I am envisioning it more like a volumetric material or OSL script.

So…imagine running a process like you just did, except within a volumetric material. The lines would represent the areas of the GREATEST density, and between the lines, the density would fade to zero. Essentially it would be a series of waves made of dense areas in a volumetric function. And here, this is where a truly 3-dimensional set of equation would make a difference. Now, I know that TECHNICALLY, magnetism is a constant field. But, this is a representation. So, from a sphere, emanating from the poles would be a series of lines just like you have. Except, instead of the lines, they would be rings of a dense material. Obviously, if those densities were allowed to be 100% it would entirely hide the object, but left with a certain amount of transparency, we would be viewing the magnetic field lines in 3d space.

http://bugman123.com/Physics/MagneticPool1.jpg

I have no idea how one would do it with volumetrics, unless you can include multiple objects in the calculations…but this image is more like what I would want to accomplish at the end of the day (although in 3d, and probably with just two objects). This is a 2d dimensional calculation (there is an associated video clip: http://bugman123.com/Physics/MagneticPool1.mov) that shows multiple field lines interacting.

Am I explaining this well? Its almost like, if every one of the lines in your simulation were a revolved surface instead of a line. And then, instead of just a revolved surface, each line was actually a density wave.

On further thought…I am thinking of something else. Since this particular problem involves something (the MFL) REACTING to another object…really what we are describing is a series of densities within a volumetric domain. In this sense…a fire or smoke simulation reworked from scratch actually offers the appropriate work space…

first I did not really find the 3D math for this
which I think use the elecmag Maxwell equations
and I don’t really have math solution in 3D for that !
let me know if you have it !

now It would be possible to copy and rotate the curves I did and may be add a bevel curve with a volume texture
but not certain if a gradient would be nice as a render!

the idea of using smoke or fire !
well not certain how this could be done and what kind of render it would give !

it is a difficult model to do and to represent it in 3D!

and to have field interaction
I know it is possible with particles but have to find how to!

may be other peoples can bring some ideas here

http://www.mathcurve.com/courbes2d/magneticcirculaire/magneticcirculaire.shtml

got this 3D way but not certain how to do it around wires and overall
http://www.bing.com/images/search?q=magnetic+lines&qpvt=magnetic+lines&FORM=IGRE#view=detail&id=B52A8FFC4DB54EAA04B8598F4C172F287E21F053&selectedIndex=486

happy bl

this is quite an interesting problem!!! :slight_smile:

I haven’t tried it yet, but I can see some problems in how to model this (at least only with nodes):

For a simple bar magnet, it shouldn’t be difficult at all; even for a two or three magnets.
The problem however becomes more complicated with electric coils, much because each point of the coil will have its own influence on the field, and this would mean that we need to add up the potencial vector of all points.

A better solution would be to use OSL, since it’s possible to have loops and arrays/collections, but for a volumetric material, this can turn render times into a nightmare. :frowning:

Another thing we must consider, is that the field itself doesn’t produce any lines, thought something like the sin(a*potencial) can give some satisfactory results.

this might take a while to complete a nice 3D model!

1 - POVRAY script
I never work with POVRAY before
may be someone else can give some feedback if possible to do in blender ?
can you give link to the POVRAY script !

2 - using particles might be a way to get a nice 3D model

3 - I will upload later on the script
have to make a new stand alone version for it !

4 - here is model from French math link


happy bl

I never work with POVRAY and don’t understand how it works!
so is there anyone who knows how to convert this python or explain how it works to make a python script !

here is POVRAY sample for the script

//************************************************** ****************************************
//* Magnetic Field of a Solenoid, copyright by Paul Nylander, bugman123.com, 5/17/06
//* runtime: 1 minute
//************************************************** ****************************************

#declare mu0=1.25663706144e-6; #declare n=6; #declare R=0.01; #declare dL=(4/3)R; #declare r=R/4;
camera{location <13.65,0,16.25>R look_at 0.4R
x up -y right ximage_width/image_height sky -y angle 25}
light_source{<0,0,8
R>,1}

//Solenoid
#include “golds.inc”
#declare begin=1; #declare x1=(0.25-n/2)dL;
#while(x1<=(n/2-0.25)dL)
#declare theta=2
pi
(x1/dL+n/2); #declare p2=<x1,Rsin(theta),-Rcos(theta)>;
sphere{p2,r texture{T_Gold_5A}} #if(!begin) cylinder{p1,p2,r texture{T_Gold_1A}} #end
#declare begin=0; #declare p1=p2; #declare x1=x1+0.005*dL;
#end

//Electromagnetic Field
#declare Sqr=function(X) {X*X};

#declare sign=function(i1) {1-2floor(2mod((i1-1)/2,n)/n)}; // i1<n1?1:-1

#declare I=function(i1) {sign(i1)}; // current

#declare xcoil=function(i1) {(4/3)R(mod(i1-1,n)+0.5floor(2mod((i1-1)/2,n)/n)-0.5*(n-0.5))};
#declare B=function{(mu0/(2pi))sqrt( // magnetic field magnitude
Sqr(sum(i1,1,2
n,I(i1)
(y-sign(i1)R)/(Sqr(x-xcoil(i1))+Sqr(y-sign(i1)R))))+
Sqr(sum(i1,1,2
n,I(i1)
(x-xcoil(i1))/(Sqr(x-xcoil(i1))+Sqr(y-sign(i1)*R))))
)}

#declare contours=function{(2+cos(0.06pi(sum(i1,1,2*n,I(i 1)/sqrt(Sqr(x-xcoil(i1))+Sqr(y-sign(i1)R))))))/3} // magnetic field line contours
plane{<0,0,1>,0
pigment{function{min(1,max(0,12000
B(x,y,0)*contou rs(x,y,0)))} color_map{
[0 rgbt <0,0,1,1>] [0.25 rgbt <0,0,1,0.75>] [0.5 rgbt <1/3,0,1,0.5>] [0.75 rgbt <2/3,0.5,1,0.25>] [1 rgbt <1,1,1,0>]
}}
finish{ambient 2.25 reflection 0 diffuse 0 specular 0}
}

happy bl

arcarsenal

can you upload pic for the solenoid POVRAY so we know how it looks

I did a quick test for lines in 3D


happy bl

Cool script, RickyBlender! :slight_smile:

I found this doc about visualizing vector fields, that is also quite interesting. Maybe this can be usefull for creating a 2dTexture… And quiçà, volumetrics.

interesting way to do it but not really implemented in python / blender yet !

and like I said playing with vector fields in 3D is a difficult task !

but I think will find something simpler and easy to do in blender

would like to see an example of force field type magnetic with particles.

thanks\happy bl

did a model here with arrows and curve
what do you think ?


happy bl

The POV-RAY script above (although the author used Mathematica to help) is the literal script he offered for describing this image:

http://bugman123.com/Physics/Solenoid.jpg

What is interesting to me is that while RickyBlender has done a great job at now having created a 3-dimensional representation of the field lines as revolved planar elements, the suggests for producing a true 3-dimensional representation still come back to a question of: 1) volumetric shaders, 2) OSL shaders, or 3) Particles. For these, the basic input ought to be something that is related to what RickyBlender is doing with digitizing the information from the French link provided above.

Here, POV-RAY takes a Bounding Box as a 3-dimensional domain and voxelizes its interior according to whatever script is provided by the user: http://www.mpa-garching.mpg.de/~mselig/povray/povray.html

http://www.mpa-garching.mpg.de/~mselig/povray/povray01.png

As we can see, one benefit here is that the entire Volumetric domain is specifically scripted by the user. Beyond that, however, is how this method starts to look like a Volumetric OSL shader in Blender, but is also reminiscent of the Volumetric domain declared by a smoke/fire sim, which is then voxelized and looks remarkably like this POV-RAY density example. I also just peeked at Secrop’s link, and on (I believe) page 34, there are several images of vectors showing airflow over a tire (or something like that), but it is very similar to the above: a cubic domain and voxelized densities along vector paths.

So, in a certain sense, I feel that if one were working with a Volumetric shader in a simple cubic domain, the only difference between an OSL shader and the POV-RAY representation would be the language it is written in.

However, if this approach is taken, i want to avoid a simple depiction/representation of 3-dimensional MFLs…which, while interesting, we could do just as easily with concentric ellipses that “look right”. What is far more interesting than a representation is a SIMULATION…which is why I am really eager to see how RickyBlender’s script is operationalizing the above equations. Beyond drawing Field Lines, there is the issue of interaction among field lines of two objects. With no second object within the domain, the field lies will look the same. However, upon producing a second object in the domain, rather than depicting two objects with two independent sets of Field lines that do not interact and simply intersect, a simulation would instead draw the lines repulsing and curving together.

So…depending on the approach…I think there is a problem of “perspective” that I lack the language to describe, other than simply calling it the “inside-out problem” and it has to do with whether we are taking our object of interest as the lines themselves, or the volume of the domain.

For what I mean by this, I refer back to Secrop’s comment that “the field itself doesn’t produce any lines”. This is true, and I kind of mentioned it before…the MFL’s a representations of the magnetic field. So there are two approaches. The first, and no less impressive, is the approach of RickyBlender. He takes the vector lines as the object and draws them in space. With a single magnetic object in the domain, this is fine as most of the lines will be closed and concentric. However, when a second object is added, I suspect that the complexity of the lines in a true simulation will become much more difficult to draw, as often that will become twisted and bent and parabolic, eschewing a closed ellipse.

The second approach takes to heart Secrop’s comment above. The key to this is that the object of interest is not necessarily the lines themselves, but the volume, and not just the volume, but the volume as a medium. To think of the classic depiction of magnetic field lines, the lines themselves are not the medium. Rather, the iron filings sprinkled on the paper are the medium. At first, the iron filings are evenly distributed on the paper. In the presence of the magnetic field, the filings are forced to bunch up, drawing the lines not as independent vectors, but rather as areas of density.

So…I think maybe there are two pursuits here. One, RickyBlender’s (man…I keep wanting to say RickyBobby…I hope I didn’t accidentally type that anywhere) script, seeing how far that can be taken toward drawing MFLs as vectors. Or two…using either particles or an OSL volume or something to set up an evenly distributed medium, and then in the presence of objects simulating the reaction of that medium to those objects.

Until I see RickyBlender’s script, I will trawl through the resources that have already come up…and, since I am new to both OSL and POV-RAY (if it is useful or enlightening remains to be seen)…investigating how they draw volumes.

I really appreciate the comments here. Even if there is no smashing success at the end of the road, I think this is interesting to think about.

o know there is sort of a magnetic field thing!
but have not played with that one
so have to find a good example with a tut may be!

and I think with that you can set 2 fields in interaction
hope someone can show an example for this effect

and not certain yet how it would look

now for volume voxel
I will look for this effect and if something can be done nicely in blender !

give me till tomorrow for the little script
I will correct a few things and upload it
but this will basically give only the shape for the lines

so not really very useful!

happy bl

did you ask question in the physic forum I think
for interacting fields for magnets!

may be someone has seen this type if physic !

happy bl

If you want to simulate the lines in 3D, couldn’t you just create several concentric tori with transparent skins?

Here’s a good physical demonstration.

Megacal,

Yeah, this is essentially what we are talking about. RickyBlender’s script drawing the field lines in 2d, if made 3d becomes exactly what you are talking about. But from there, the brainstorming has moved more toward, not specifically drawing the lines (or the tori(toruses?)), but rather “deriving” the lines/tori as densities/volumes/voxels/whatever.

Ultimately this whole thing is going to end up, like Ricky said, in the physics/simulation forum, but I placed it here initially under the idea that someone may have already tried something like this as a volume/OSL shader (without having yet thought that it might make more sense as a voxelized particle simulation).

But…first things first. It has been years since I have done much math or physics, and even then I was really only comfortable with partial derivatives in Euclidean space. So I am looking forward to analyzing RickyBlender’s script and really focusing on how to operationalize increasingly complex equations and to draw them on-screen as discrete functions. Now…people that are better at all of this than me, I would love if they jumped in and figured it all out and I would be plenty happy following behind and trying to understand how they did it. But, if that isn’t the case, then I consider it a fun exercise that will force me to remember some old skills and develop some new ones.

here is small script for doing the 2 types of lines in 2D

just run script in text editor
then in the add mesh on bottom header select last entry for magnetic and select first option
it will add the 2 curve as mesh object.

zmag1.blend (117 KB)

sorry don’t go often to the other forum!
if you get something let us know!

happy bl

1 Like

Maxwell’s Equations gives you everything you need to plot in 3D. Take a uniform density of points located in the region of interest, plug those coordinates into the solution for the B field strength and plot the magnitude proportionally brighter as the magnitude at the point.
Not enough resolution? Use more points per volume. Soon you will be slicing up your 3D object in order to see details. Of course, you can post process the results to show lines of stepped magnitude that are actually usable. It’s that simple.
Remember that Maxwell’s equations in their original form don’t take into account relativity or QED. Good luck with those as researchers have hit that wall in containment design of fusion reactors and plasma behavior. Enjoy.

1 Like