📄 initialization.m
字号:
Bline_length = B_parameters(1) * 100 * [top_length, top_length, top_length, top_length, top_length, bottom_length, bottom_length, bottom_length, bottom_length, bottom_length, top_length, top_length, top_length, top_length, bottom_length, bottom_length, bottom_length, bottom_length ];
otherwise
spline_pos = [ -1 1 1; 2 0 -1; 2 2 0; 0 2 1; -2 2 2; -2 0 1; -2 -2 0; 0 -2 -1; 2 -2 -2; 1 1 -1; -2 0 -1; -2 2 0; 0 -2 1; -2 2 2; 2 0 1; 2 -2 0; 0 2 -1; 2 -2 -2 ]; % starting point of splines, which represent field lines
%spline_pos = [ 2.6,0,0;094,0,0.034202;0766,0,0.064279;05,0,0.086603;0174,0,0.098481;2.4826,0,0.098481;2.45,0,0.086603;2.4234,0,0.064279;2.406,0,0.034202;2.4,0,1.2246e-017;2.406,0,-0.034202;2.4234,0,-0.064279;2.45,0,-0.086603;2.4826,0,-0.098481;0174,0,-0.098481;05,0,-0.086603;0766,0,-0.064279;094,0,-0.034202];
Bline_length = 0.2*[100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ];
end
if get( handles.popMagField, 'Value' ) > 1 % if any of magnetic field is chosen
for i = 1:length( spline_pos )
if i <= length( spline_pos )/2 % second half of spline_pos point are the same like first half, but they are used to generate spline in other directions
direction = 1;
else
direction = -1;
end
Bfield_lines(i) = struct( 'spline', Calculate_spline( spline_pos(i,1:3),handles, direction, BFIELD_LINE, i, Bline_length(i) ) );
end
else % if no magnetic field is chosen
for i = 1:length( spline_pos )
Bfield_lines(i) = struct( 'spline', []);
end
end;
% initialize electric field lines; the same like magnetic field
%spline_pos = [ 0 0 0.1; 2 0 -2; 2 2 0; 0 2 2; -2 2 3; -2 0 2; -2 -2 0; 0 -2 -2; 2 -2 -3; 0 0 0.1; 2 0 -2; 2 2 0; 0 2 2; -2 2 3; -2 0 2; -2 -2 0; 0 -2 -2; 2 -2 -3 ];
spline_pos = [ 0 0 0; 0 1 0; 0 1 1; 0 0 1; 0 -1 1; 0 -1 0; 0 -1 -1; 0 0 -1; 0 1 -1; 0 2 0; 0 2 2; 0 0 2; 0 -2 2; 0 -2 0; 0 -2 -2; 0 0 -2; 0 2 -2; 0 0 3 ]; % starting point of splines, which represent field lines
%spline_pos = [ -50 -100 -10.1; -40 -100 -10; -40 -101 -10; -50 -101 -10; -60 -101 -10; -60 -100 -10; -60 -100 -10; -50 -100 -10; -40 -100 -10; -50 -100 -10; -40 -100 -10; -40 -101 -10; -50 -101 -10; -60 -101 -10; -60 -100 -10; -60 -101 -10; -50 -100 -10; -40 -100 -10 ]; % starting point of splines, which represent field lines
Eline_length = [12640, 12640, 12640, 12640, 12640, 12640, 12640, 12640, 12640, 12640, 12640, 12640, 12640, 12640, 12640, 12640, 12640, 12640 ];
if get( handles.popElecField, 'Value' ) > 1 % if any of electric field is chosen
for i = 1:length( spline_pos )
if i <= length(spline_pos)/2 % second half of spline_pos point are the same like first half, but they are used to generate spline in other directions
direction = 1;
else
direction = -1;
end
Efield_lines(i) = struct( 'spline', Calculate_spline( spline_pos(i,1:3),handles, direction, EFIELD_LINE, i, Eline_length(i) ) );
end
else % if no electric field is chosen
for i = 1:length( spline_pos )
Efield_lines(i) = struct( 'spline', [] );
end
end;
end
% ******** calculates spline ***********************************************
function spline = Calculate_spline( position, handles, direction, field, line_num, line_length )
% calculates one spline of magnetic or electric field. the parameter
% direction is not in use atm
global_variables;
absolute_time = -1;
switch field
case EFIELD_LINE
[l,spline] = ode15s( @calculate_E,[0 line_length],position );
case BFIELD_LINE
[l,spline] = ode15s( @calculate_B,[0 line_length],position );
end
end
% *********** sets virtual reality world magnetic and electric field lines
function w = make_vr(simfile, Bfield_lines, Efield_lines);
w = vrworld(simfile); % updating virtual world
open(w);
temp = get(w,'Figures');
if length(temp) == 0
view(w);
set(w,'TimeSource','external');
%view(w, '-web');
end
alpha = [0: pi./10 : 2*pi]';
cross = 0.01*[cos(alpha) -sin(alpha)];
for i = 1:length(Bfield_lines) % updating magnetic field lines
if i <= length(Bfield_lines)/2
tmp_num = i;
else
tmp_num = i+1;
end
name_line = strcat('B', num2str(tmp_num), '_spine');
line = vrnode(w, name_line);
if length(Bfield_lines(i).spline) > 0
%temp1 = field_lines(i).spline;
line.spine = Bfield_lines(i).spline;
else
line.spine = [];
end;
line.crossSection = cross;
% TODO: crossSection of a magnetic field line could represent the
% strength of the magnetic field in the particular area
line.solid = true;
end;
for i = 1:length(Efield_lines) % updating electric field lines
if i <= length(Efield_lines)/2
tmp_num = i;
else
tmp_num = i+1;
end
name_line = strcat('E', num2str(tmp_num), '_spine');
line = vrnode(w, name_line);
if length(Efield_lines(i).spline) > 0
%temp1 = field_lines(i).spline;
line.spine = Efield_lines(i).spline;
else
line.spine = [];
end;
line.crossSection = cross;
% TODO: crossSection of a electric field line could represent the
% strength of the electric field in the particular area
line.solid = true;
end;
w.trajectory_spine.spine = [0 0 0; 0 0 0];
w.trajectory_spine.crossSection = cross;
w.guide_spine.spine = [0 0 0; 0 0 0];
w.guide_spine.crossSection = cross;
save(w, get(w, 'FileName'));
vrdrawnow;
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -