# How to generate sloped streamslice plot of magnetic field in Matlab

I am currently working on my bachelor thesis, where I am calculating trajectory of electrons and ions in Hall Effect Ion Thruster. However, to be sure what I am calculating, I need to know how does the electromagnetic field look like.

I already have working code for visualization of electromagnetic field using streamslice, however I would like to take it to the next level.

I have created coordinates $x,$ $y$ and $z$ through meshgrid and computated magnetic field, which is set of not really pretty equations. Electric field points only towards the $z$ direction.

Here is the snappet of code that is generating picture below:

% Magnetic field
plot_field = streamslice(x,y,z,Bx,By,Bz,0.02,0.02,0);
set(plot_field,'Color','black','LineWidth',2);

% Electric field
hold on;
quiver3(x_el,y_el,z_el,Ex,Ey,Ez,1,'r');
hold off;

% Plot of discharge chamber
[x_ch, y_ch, z_ch] = cylinder(0.4,40);
z_ch(1,:) = -0.2;
z_ch(2,:) = 0.2;

hold on;
plot_ch = surf(x_ch,y_ch,z_ch);
hold off;
set(plot_ch,...
'LineWidth',1,...
'FaceAlpha',0.5,...
'EdgeColor','black',...
'EdgeAlpha',0.6,...
'DiffuseStrength',1,...
'AmbientStrength',1);


This code generates the following,

Question

I would like to create streamslice of the magnetic field in various degrees slope (let's say $45$), so I could see how does the field looks like not only when intersecting magnetic dipoles, but also in other locations. That would be great for study of particle motion.

-

## migrated from physics.stackexchange.comMay 7 '13 at 20:54

This question came from our site for active researchers, academics and students of physics.

It is possible to draw a streamslice slicing using non-planar or at arbitrary angle. You can use rotate command to rotate your slicing plane(s). Your plot_field object can be modified by adding several lines

slicing = surf(linspace(-1,1,10),linspace(-1,1,10),zeros(10));
% third input: rotating angle
% second input: the vector to which you are rotating your data with respect
rotate(slicing,[0,0,0],45);
xs = get(slicing,'XData');
ys = get(slicing,'YData');
zs = get(slicing,'ZData');
plot_field = streamslice(x,y,z,Bx,By,Bz,xs,ys,zs);


Also contourslice is another my own favorite to visualize electromagnetic field: http://www.mathworks.com/help/matlab/ref/contourslice.html

If you know how to use VTK, then you can export your 3D vector data to a vtk file using: http://www.mathworks.com/matlabcentral/fileexchange/34310-matlab-3d-vectors-to-paraview-via-binary-vtk-file

Then you could use software like Paraview to visualize vector field as you like, for example, slicing at $45^{\circ}$ degree of the box like you said (I used the data of my own from a dielectric with a cavity Maxwell pde):

-