Wednesday, November 17, 2010
Sorry to write an entire story here but,
It’s been a while since I last posted and I wanted to bring you guys up to date on my effort to develop a user friendly platform from which the group members here could fairly easily develop, view (in 3D) and use the electric and magnetic field lines/densities of different magrid coil configurations quantitatively.
I first thought that using math programs such as Mathematica, Octave or Maple would be the best platform choice. But after experimenting with Mathematica, I now see that, in my opinion, these math type programs lack a critical conceptual capability necessary for clear 3D understanding by most users. i.e., the ability by the user to rotate, scale and translate 3D output objects on their computer monitor screen in real-time.
Please, let me explain some basic 3D stuff:
[ BASIC 3D COMPUTER GRAPHICS ] Found on the internet (a long time ago).
Create a set of 3D points/vectors (x,y,z). Using this you can create all sorts of 3D shapes, but then you reach the problem. How do I put it on my 2D screen? This is actually very easy to do. All you do is use the following two formulas:
X2D=X3D/Z3D
Y2D=Y3D/Z3D
…Where X2D and Y2D represent the X and Y components of the pixels on your 2D computer monitor.
After this you will have to multiply the two results by the width(X) and height(Y) of your screen respectively because this assumes that the width and height of your screen are both one. Otherwise your shapes will seem stretched or contracted.
Of course it isn't as simple as that because you will not be able to move at all and you will have points behind you shown as well. To handle this you create a camera.
The camera will just be the point that you are looking from. You make the camera from a single 3D point/vector. To apply the camera to the 3D points in your model you simply subtract the camera's coordinates from each 3D point’s coordinates.
X3D = P3D.x - Cam.x
Y3D = P3D.y - Cam.y
Z3D = P3D.z - Cam.z
Now we need to remove anything behind the camera that you can't see. If a point’s Z coordinate is less than 0 then we don't draw the point. This is best done when you are actually transferring the point(s) from the 3D model onto the 2D screen because you can simply not draw it.
One uses vector matrix math to rotate, scale and translate sets of 3D points so that they will move about as viewed within the 2D camera’s screen. or vice-versa.
That’s a brief overview of 3D computer graphics.
I have discovered the publicly available source code to a simple yet powerful 3D-Engine (program) written in Microsoft Visual Basic by a man named Jerry Chen called Dex3D. He wrote and published it back in 1999. The Visual Basic source code for Dex3D is freely available to download at both the ‘Planet Source Code’ and ‘CodeGuru’ web sites. This program does not use OpenGL, it is a compact and simple, self-contained, real-time 3D engine written entirely in Visual Basic.
Note: the download version of the Dex3D program contains a HUGE cpu-hog programming error (Mr. Chen included an infinite Do-Loop to perform screen rendering updates – whether the screen needed rendering or NOT). Except for the infinite Do-Loop error, the program is an absolute 3D gem!
I quickly made the necessary changes to convert it into a purely event-driven program as it should be. In my modified version the program is now an efficient and relatively simple 3D jewel!
Unfortunately the source code is undocumented. But its programming statements are so well written that a good programmer (who understands basic 3D) can quickly determine what Mr. Chen is doing.
On the high-level, it took me a while to determine that all you have to do is keep track of the sequential integer values returned for each 3D-mesh (independent 3D-Object) created (returned) from his mesh drawing commands. You can then simply apply his matrix mesh-transformations to these integer-referenced drawing meshes to rotate, scale and translate them independently as you wish.
With the Dex3D program the user can (in real-time) spin any 3D object(s) just by clicking and dragging the mouse pointer about the program’s 3D view.
I have modified the program to create several magrid coil configurations and to both load and save ascii text formatted user-definable magrid files. This file input capability will allow users here to generate their own magrid configurations, load them and view the electric and magnetic fields generated by them in 3D.
Each line in a magrid file represents the sequential 3D points of the magrid’s individual coils (see below), where R,G,B represents the red, green and blue color components of a given 3D point.
ASCII text file format:
X,Y,Z,CoilNum,R,G,B
Example sequential 3D point definition lines in a magrid file:
-1,.9801725,.1981461,1,255,0,0
-1,.9555728,.2947552,1,255,0,0
-1,.9214762,.3884348,1,255,0,0
...
Shown below is a spherized single coil octahedron magrid (loaded from an ASCII text file) that I can spin around in real time with the mouse and perform Biot-Savart summations upon its coil-segments within the program.
Single coil, Spherized Octahedron Magrid
For the last two weeks, I’ve been very busy modifying this program to work with magrid analysis.
Currently, I’m adding the ability to draw selective sets of the 3D magnetic field lines generated around the magrid’s coil segments (transferring from a 2D version). The program is too crude to release now – I’m working the bugs out. But, so far, it’s a super cool 3D program to play with!
I’ll figure out a way for you guys to download it (source code included) when I get the first workable ‘magrided’ version ready.
~Randy