# electromagnetic field representation???

Hi, i was thinking about starting a new script in order to represent an electromagnetic field…

Unluckily, i don’t really know the physical laws of that kind of system so it will need some thours of research before to start to write a script…

but maybe that kind of script already exists or could be written from a similar one… All that i know is that it already exists in a plugin named ‘electric field solver’ for Rhino3D.

I think it could be a good idea to work on that kind of script for particles, for example, but i’m really stuck by the mathematical and physical knowledge it needs:(

Does somebody could suggest me some tracks or rules to follow?

Cheers

Here’s something that I found earlier this summer about magnets. I’m not sure about the accuracy of the physical laws that define the actions, but the .blend seems to be realistic enough to fake magnetic effects.

I think how you want to represent this is highly dependent on what you want to exist. I assume when you say field lines, you’re talking about the elliptical patterns that you see from using iron filings with a bar magnet. If thats the case, then generally its just par- ellipses between the two poles (they aren’t exact ellipses, though).

If thats the case, and you want an approximation, you could work your way around the sides of the bar magnet, evaluating equations of ellipses (given things like magnetic field density, strength, etc., these won’t likely be actual physical units, just ones you can input), and then placing vertices and possibly edges in the proper positions. It could be an interesting exercise in recursion of you really think about and plan it out right.

A good place to start for research is wikipedia. Like this: http://en.wikipedia.org/wiki/Magnetic_field, or in whatever language you prefer. A lot of time they have decent links to things that can really help you out with stuff like this. Of course there is always Google.

Upon a little googling I came up with Maxwell’s equations on this subject: http://en.wikipedia.org/wiki/Maxwell’s_equations

In case you’re playing with the spmg.blend file in my link, I just found a small error. In the scene “basic” you need to add a property named “force” with a value of 1.700 to the Empty.

thanks forte!

this something like that i would try to experiment. i will post some results last week i hope.

Hi, i’m still working on this script but actually i’m stuck by a lack of physics knowledge. I’m trying to represent the multipole electric field from two lists: one for the electric field (‘pointsgrid’) and one for the charges (‘cpointlist’). The ‘pointsgridlist’ contains a list of coordinates [x,y,z] and the ‘cpointlist’ contains a list of Blender objects with their charges sign (positive = 1, negative = 0) as following:

pointsgridlist = [[x,y,z],[x,y,z],[x,y,z],[x,y,z],…]
cpointlist = [[Object,sign],[Object,sign],[Object,sign],[Object,sign],…]

for each points of pointsgridlist the script calculates the sum of the field in X, Y and Z coordinates and then dram a mesh line from the point to the new X,Y,Z coordinates.

Its returning a really strange result, every lines are oriented to the center of pointsgridlist and their length is incredibly huge.:eek:

here is the code:

``````

for points in pointsgrid:

X = 0
Y = 0
Z = 0

for cpoints in cpointlist:

if cpoints[1] == 1:

Q = 1

else:

Q = -1

EX = (Q/(4*math.pi*(8.8542/1000000000000)))*\
(points[0]-cpoints[0].getLocation()[0]/\
(((points[0]-cpoints[0].getLocation()[0])**2)**(3/2)))

EY = (Q/(4*math.pi*(8.8542/1000000000000)))*\
(points[1]-cpoints[0].getLocation()[1]/\
(((points[1]-cpoints[0].getLocation()[1])**2)**(3/2)))

EZ = (Q/(4*math.pi*(8.8542/1000000000000)))*\
(points[2]-cpoints[0].getLocation()[2]/\
(((points[2]-cpoints[0].getLocation()[2])**2)**(3/2)))

X += EX
Y += EY
Z += EZ

vob = Object.New('Mesh','VectorField')
me = Mesh.New('VecLine')
coords = [[points[0],points[1],points[2]],[X,Y,Z]]
me.verts.extend(coords)
me.edges.extend(me.verts[0],me.verts[1])
scn = Scene.GetCurrent()
vob.layers = [2]
Redraw()

``````

Anybody good with physics?
I really hope to fix that

I think the problem is located at the calculation of the field E for each coordinates Ex, Ey, and Ez. I based my script on a formula but maybe i did a mistake while translating it into my script :eek:?

Finally, some better outputs are coming:

Here the code, don’t forget that you need to add some lines before the followings. you need to have a list of points (a grid or vertex from a mesh,…) named ‘pointsgrid’ and list of charge points named ‘cpointlist’ with data organized as following : [[Blender Object,sign],…]. Actually sign is 1 for positive charge and 0 for negatives ones. ‘Q’ is the amount of the charge (actually: 1). You can change any of this settings to fit with your code. And if you make something more efficient don’t hesitate do reply.

``````

for points in pointsgrid:

X = 0.0
Y = 0.0
Z = 0.0

for cpoints in cpointlist:

if cpoints[1] == 1:

Q = 1

else:

Q = -1

d = ((cpoints[0].getLocation()[0]-points[0])**2+\
(cpoints[0].getLocation()[1]-points[1])**2)**0.5
ratio = 0.5/d

EX = (Q/((4*math.pi)*(8.8542*math.pow(10,-12))*\
(cpoints[0].getLocation()[0]-points[0])**2))#*ratio

EY = (Q/((4*math.pi)*(8.8542*math.pow(10,-12))*\
(cpoints[0].getLocation()[1]-points[1])**2))#*ratio

X += EX
Y += EY

CX = (X*0.9)/(((points[0]-X)**2+(points[1]-Y)**2)**0.5)
CY = (Y*0.9)/(((points[0]-X)**2+(points[1]-Y)**2)**0.5)
X = (CX+points[0])
Y = (CY+points[1])

vob = Object.New('Mesh','VectorField')
me = Mesh.New('VecLine')
coords = [[points[0],points[1],points[2]],[X,Y,Z]]
me.verts.extend(coords)
me.edges.extend(me.verts[0],me.verts[1])
scn = Scene.GetCurrent()
vob.layers = [2]
Redraw()

``````

I realize this thread is super old, but for some reason still open - so I’ll ask: did you ever get any success with this?
The leading EM solver software CST Studio can only be afforded by universities and large corporations. There must be many people from hobbyists to professionals wanting a good FOSS EM simulator. I did find Vizimag which is free, but 2D-only and Windows-only.
Perhaps the most promising find was a thread discussing open source EM simulators indicating that there are many open source libraries available for doing most of the tricky computation. They just need a GUI? Well Blender could provide the GUI if someone could figure out how to tie all this stuff together into a fancy Python script. Or at least that’s the impression I got. Any thoughts?

I’m guessing Blender could probably be made to handle simulation for these sorts of meshes:

Notice the topology of the mesh has been reconstructed in tetrahedral patterns where areas of finer detail have denser triangles.
This PDF explains a bit about tetrahedral meshing.

Although for more detailed designs such as this circuit board Blender may not be precise enough.
Or then again maybe it is?

Any sort of ability to simulate EM fields would be great to have. It’s not my expertise, but I am very curious if it can be implemented.